Xslt- preceding-sibling within for-each
14,397
<xsl:for-each select="Services/ServiceBooking[not(ServiceID = preceding-sibling::ServiceBooking/ServiceID)]">
should do but you should learn about Muenchian grouping in XSLT 1.0 or for-each-group
in XSLT 2.0.
Author by
Gísli Freyr Svavarsson
Updated on June 14, 2022Comments
-
Gísli Freyr Svavarsson almost 2 years
So I have this xml code and two of the nodes have the same ID-value. How can I not display the same node if it has the same value as a preceding-sibling?
That is if A = 12, B = 10, C = !2. The Xslt file shouldn't display C as it has the same value as A.
here the XML
<Services> <ServiceBooking> <ID>A</ID> <ServiceID>12</ServiceID> </ServiceBooking> <ServiceBooking> <ID>B</ID> <ServiceID>10</ServiceID> </ServiceBooking> <ServiceBooking> <ID>C</ID> <ServiceID>12</ServiceID> </ServiceBooking> </services>
and the Xslt
<xsl:for-each select="Services/ServiceBooking[not(preceding-sibling::ServiceID)]"> <tr> <td class="name"><xsl:value-of select="ID" /></td> <td><xsl:value-of select="ServiceID"/></td> </tr> </xsl:for-each>
Can anyone of you guys help me with this?
mvh