XPath 轴是否尊重 Xslt 排序? [英] Do XPath axes respect Xslt sorting?

查看:33
本文介绍了XPath 轴是否尊重 Xslt 排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我像这样调用 xslt 模板:

If I call an xslt template like so:

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

下面模板中的 following-sibling 轴会询问文档顺序还是排序顺序?

Will the following-sibling axis in the template below interrogate the document order or the 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>

推荐答案

XSLT 获取输入树并将其转换为结果树,您的路径表达式始终对输入树进行操作,因此您要查找的任何兄弟都可以导航到输入树.使用 XSLT 2.0(或使用 XSLT 1.0 和像 exsl:node-set http://www.exslt.org/exsl/index.html) 您可以使用临时树创建变量,然后您可以在其中导航,例如

XSLT takes an input tree and transforms it into a result tree, your path expressions always operate on the input tree so any siblings you are looking for are navigated to in the input tree. With XSLT 2.0 (or with XSLT 1.0 and an extension function like exsl:node-set http://www.exslt.org/exsl/index.html) you can create variables with temporary trees you can then navigate in e.g.

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

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

would then process a temporary node-set of Step elements which have been sorted.

使用 XSLT 2.0,您不需要 exsl:node-set 调用.

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

这篇关于XPath 轴是否尊重 Xslt 排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆