What you need to use is "position()", here is a stupid example but hopefully it will help you:
the start of your loop (dont use my select statement, it might be different in you case its just an example) <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:choose> What this does is, when the loop hits the first item <xsl:when test="position() = 1"> Do something with the first item <xsl:when> Now this is when it loops through the rest <xsl:when test="position() >= 2"> Do something with the rest <xsl:when> <xsl:choose> <xsl:for-each>
PS: Actually, Frederik - you *are* allowed to write >= inside a string value. The only characters you MUST escape at all times are the ampersand ( & ) and the less-than ( < ) characters. That means that if you don't like to write this:
<xsl:if test="somePropertyValue < 500">
You can rewrite it like this, and it'll be valid:
<xsl:if test="500 > somePropertyValue">
- but my head doesn't like that way of comparing at all :-)
First subnode
I have an xslt macro which loops through a set of items. I need to get a piece of information from the first of each set.
How do I use an attribute from the first item?
Great! Finally something i think i can help with.
What you need to use is "position()", here is a stupid example but hopefully it will help you:
Ok, going to double post because the forum changes my text each time i edit,
This is wrong:
Hi Geoff,
Taking an attribute from the first of somethings in a set is done by appending a [1] predicate before the attribute selector, e.g.:
If you need to go through them all anyway, use Frederik's suggestion and test whether you're at the first item - same example:
/Chriztian
PS: Actually, Frederik - you *are* allowed to write >= inside a string value. The only characters you MUST escape at all times are the ampersand ( & ) and the less-than ( < ) characters. That means that if you don't like to write this:
You can rewrite it like this, and it'll be valid:
- but my head doesn't like that way of comparing at all :-)
Why does using
<a href="{umbraco.library:NiceUrl($cell/event[1]/@id)}">
just give me a System.OverflowException error? I don't understand.
How can I check if an element exists in the array?
Oh okay, I figured it out, there was no checking to verify there was a value present, so it was failing on those grounds.
is working on a reply...