Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XPath轴是否尊重Xslt排序?_Xslt_Sorting_Xpath - Fatal编程技术网

XPath轴是否尊重Xslt排序?

XPath轴是否尊重Xslt排序?,xslt,sorting,xpath,Xslt,Sorting,Xpath,如果我这样调用xslt模板: <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>

如果我这样调用xslt模板:

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

XSLT获取输入树并将其转换为结果树,路径表达式始终在输入树上运行,因此您要查找的任何同级都会在输入树中导航到。使用XSLT 2.0(或XSLT 1.0和诸如exsl:node set之类的扩展函数),您可以使用临时树创建变量,然后可以在其中导航,例如

<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"/>

然后将处理已排序的步骤元素的临时节点集


使用XSLT2.0,您不需要exsl:node-set调用

XPath轴反映输入树(或临时树,如果节点位于临时树中)中节点的关系。它们与处理顺序无关(节点的以下同级节点甚至不一定是您选择处理的节点之一)

这与position()不同-认为position()告诉您节点在其树中的位置是一个常见的错误,但实际上它是节点在选定要处理的节点列表中的位置

<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"/>