Subject: Re: [xsl] Finding the first among equals using XPath From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 22 Jun 2006 12:14:10 -0400 |
<xsl:for-each select=".//X [generate-id() = generate-id(key('WXY',concat(generate-id(ancestor::W),'#',@Y))[1])]">
Cheers, Wendell
I am sure this is a hoary old one, but I could not work out the right runes to achieve it, nor the right keywords to search for to find an answer
If I have XML like the following:
<V> <W> <Z/> <X Y='0'/> <X Y='0'/> <X Y='1'/> <Z/> </W> <W> <Z/> <Z/> <X Y='0'/> <X Y='1'/> <X Y='2'/> </W> <W> <X Y='2'/> <X Y='2'/> <X Y='2'/> <Z/> <Z/> </W> </V>
I a have a for-each loop over the W elements. Inside the for-each I want to select one X with each value of Y that exists within that W.
So for the above example, for //W[1] I want to get the first and third or second and third X elements, for //W[2] I want all three X elements and for //W[3] I want any one of the X elements, but only one of them.
I hope that bit is clear.
I have run out of ideas now, so I have finally admitted defeat (a hard thing for an engineer) and am asking for your collective wisdom.
I want a node-set so I can do a for-each on that, so I would prefer to find a select specifier based on clever use of axes and predicates.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Finding the first among e, G. Ken Holman | Thread | [xsl] document() vs. current(), Marco Plum |
Re: [xsl] Finding the first among e, G. Ken Holman | Date | Re: [xsl] Merging attributes in one, Wendell Piez |
Month |