Within a foreach loop i want to use preceding-sibling::
<for-each..>
<xsl:sort select="type"/>
<xsl:when test="preceding-sibling::data[1]/type != type
the problem is that "type" within the foreach is compared with a unsorted preceding-sibling e.g.
data1/type = 1
data2/type = 2
data3/type = 1
would compare in the second loop silbling=2 (original unsorted) and type=1 (since it is sorted)
is there a way around it?
UPDATE: my intention is the following
before after
data/type2 type1 value1
data/type1 type1 value2
data/type1 and speaking in HTML a spacer here (I compare type2:value to preceding-sibling value
data/type2 type2 value1
type2 value2
I have an unsorted list of addresses where the type is a town and I need a HTML Table sorted by town and to do some stuff depending on the values and other fields (that part is working, but since the comparison with preceding-sibling is not working in a sorted for-each, I got the problem
This solution now works for me:
<xsl:variable name="sortedcopy">
<xsl:for-each select="node1/node2/node3/data">
<xsl:sort select="type" order="ascending"/>
<xsl:copy-of select="current()"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="relItems" select="MSXML:node-set($sortedcopy)" />
<xsl:for-each select="$relItems/data">
<xsl:if test="not(preceding-sibling::data[1]/id = id)">
<hr/>
</xsl:if>
<xsl:value-of select="val"/>
</xsl:for-each>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With