Will XPath describe the Xslt axis sorting?

If I call the xslt template as follows:

<xsl:template match="hist:Steps"> <dgml:Links> <xsl:apply-templates select="hist:Step"> <xsl:sort data-type="text" select="hist:End" order="ascending"/> </xsl:apply-templates> </dgml:Links> </xsl:template> 

Will the following-sibling axis in the template below poll the document order or sorted order?

  <xsl:template match="hist:Step"> <xsl:if test="following-sibling::hist:Step"> <dgml:Link> <xsl:attribute name="Source"> <xsl:value-of select="hist:Workstation"/> </xsl:attribute> <xsl:attribute name="Target"> <xsl:value-of select="following-sibling::hist:Step/hist:Workstation"/> </xsl:attribute> </dgml:Link> </xsl:if> </xsl:template> 
+4
source share
2 answers

XSLT takes the input tree and converts it to the result tree, your path expressions always work on the input tree, so any brothers and sisters you are looking for are moved to the input tree. With XSLT 2.0 (or with XSLT 1.0 and an extension function such as exsl: node -set http://www.exslt.org/exsl/index.html ) you can create variables with temporary trees then you can navigate, for example,

 <xsl:variable name="rtf1"> <xsl:for-each select="hist:Step"> <xsl:sort data-type="text" select="hist:End" order="ascending"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:variable> <xsl:apply-templates select="exsl:node-set($rtf1)/hist:Step"/> 

then it will process the temporary element of the Step node that has been sorted.

With XSLT 2.0, you don't need an exsl: node -set call.

+3
source

The XPath axes reflect the node relationships in the input tree (or the temporary tree if the node is in the temporary tree). They have nothing to do with the processing order (the next sibling node is not necessarily one of the nodes you have selected for processing).

This differs from position () - it is a common mistake to assume that position () tells you something about the position of a node in its tree, but in fact it is the position of a node in the list of nodes selected for processing.

+3
source

Source: https://habr.com/ru/post/1342433/


All Articles