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
Are you trying to group the data elements by type? Let us know what you’re trying to do and we can probably help out (as @Michael Kay said).
One option (in XSLT 2.0 or with the node-set extension) is to sorted-copy the data elements to a new variable, then run your
xsl:for-eachon the nodeset in that new variable. Then the preceding-sibling relationship will reflect the sorted order.