XSLT sorting in combination with the previous site:

In the foreach loop, I want to use before-sibling ::

<for-each..>
    <xsl:sort select="type"/>
    <xsl:when test="preceding-sibling::data[1]/type != type

the problem is that the "type" within foreach is compared with an unsorted predecessor for example

data1/type = 1 
data2/type = 2
data3/type = 1

will compare in the second cycle silbling = 2 (original unsorted) and type = 1 (since it is sorted)

Is there a way around it?

UPDATE: my intention is as follows

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 type is a city, and I need an HTML table sorted by city and do something depending on values ​​and other fields (this part works, but since comparing with the previous ones - sibling does not work in sorted for everyone, I have a problem

+5
source share
4

? , , , , ( ).

( XSLT 2.0 node) - - , xsl:for-each . .

+1

:

    <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>
+4

- , , .. . , , , , .

, , , . - , .

+1

XSLT , ,

<xsl:when test="preceding-sibling::data[1]/type != type">

<xsl:when test="not(preceding::data/type = type)">

, node node (, , ) . ( , preceding preceding-sibling, , .)

, xsl:key. ( Muenchian XSLT 1.0 xsl:for-each-group XSLT 2.0).

0

All Articles