Yes, quite easily. If you simply want to append an integer, as in your example, you can do it with the position() function. Say you want to link to all nodes of the doctype 'Page' that are not hidden:
I take you point but it does not matter in this instance...as long as the colours remain the same it works for me. I tested sorting the nodes in a different and it still goes from Green to red in the correct way.
@Laurence: Thanks! Just a link to MDN for now, but pretty soon we'll have Umbraco4Docs up and running as the perfect resource to link to for things like that :)
And good point about position()-based classnames being fragile — and rather devoid of semantic meaning. In many cases, @urlName would be more semantic (albeit still fragile, if someone renames the node):
With the @nodeName approach I guess that the most ideal approach would be to use an RegEx extension to ensure that potential special characters, space etc. is removed as well, right?
Edit: It's ideal to use @urlName, since that special chars etc. are already handled.
But yes, since @urlName is an URLified version of @nodeName, it is perfect for id and class attributes in the HTML output. Especially in HTML5, which has lifted the earlier restrictions on the id attribute.
Specify a unique class for each menu item
Is there a way i can write a top navigation XSLT so that each li that is created gets a unique ID like the following..
<ul>
<li class="link1"><a href="#">Home page</a></li>
<li class="link2" ><a href="#">Services</a></li>
<li class="link3" ><a href="#">Insulation Grants</a></li>
<li class="link4" ><a href="#">Solar PV</a></li>
<li class="link5" ><a href="#">The Green deal</a></li>
<li class="link6" ><a href="#">Book Appointment</a></li>
<li class="link7" ><a href="#">About us</a></li>
</ul>
Yes, quite easily. If you simply want to append an integer, as in your example, you can do it with the position() function. Say you want to link to all nodes of the doctype 'Page' that are not hidden:
Thanks Dan, i had got this wokring using losts of if's but of course your method makes much more sense now!
S
It's worth noting using a position might be a bad idea in the real world, as if someone sorts the nodes the position will update accordingly.
What's the markup/desired result? Maybe we can do something super nice (:
@Dan - H5UR - links in forum posts! no very many people do this, but it's really helpful (:
Thanks Uniquelau, here is another link in a forum post!
http://dev.esiscotland.co.uk/
I take you point but it does not matter in this instance...as long as the colours remain the same it works for me. I tested sorting the nodes in a different and it still goes from Green to red in the correct way.
S
@Laurence: Thanks! Just a link to MDN for now, but pretty soon we'll have Umbraco4Docs up and running as the perfect resource to link to for things like that :)
And good point about position()-based classnames being fragile — and rather devoid of semantic meaning. In many cases, @urlName would be more semantic (albeit still fragile, if someone renames the node):
With the @nodeName approach I guess that the most ideal approach would be to use an RegEx extension to ensure that potential special characters, space etc. is removed as well, right?
Edit: It's ideal to use @urlName, since that special chars etc. are already handled.
/Jan
Baaah, strike that...all that stuff is already handled by the settings in umbracoSettings.config in the /config folder. #h5is.
/Jan
@Jan: Heh, #h5youdonotsuckyoujusttypefasterthanyouthink :)
But yes, since @urlName is an URLified version of @nodeName, it is perfect for id and class attributes in the HTML output. Especially in HTML5, which has lifted the earlier restrictions on the id attribute.
Maybe the ideal semantically correct solution would be to create a variable...
<xsl:variable name="colours" select="green,blue,pink,red" />
And then select the correct colour using position() mod totalCount
I'll have a think, and post something back (: Lau
is working on a reply...