【问题标题】:How to get a particular child node collection from xml to xslt如何从 xml 获取特定的子节点集合到 xslt
【发布时间】:2015-02-19 13:40:22
【问题描述】:

我有以下 xml 文件

<htmlResponses>    
<resultSet></resultSet>
<referencePoint></referencePoint>
<htmlResponse></htmlResponse>
<htmlResponse></htmlResponse>
<htmlResponse></htmlResponse>
</htmlResponses>

我想在一个 xsl 变量中获取节点“htmlResponse”集合,这样我就可以使用 XSLT 循环遍历它。 谁能指导我如何实现这一目标?

【问题讨论】:

  • 一般不需要使用变量。如果您的 xslt 中有一个 '

标签: asp.net xml xslt xsd


【解决方案1】:

同意霍布斯,但你可以这样做:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:variable name="responses" select="//htmlResponse"/>
  <xsl:template match="/">
    ... do something ...
    <xsl:for-each select="$responses/*">
      ...
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

我能想到的唯一用例是,如果您有大量数据,并希望使用 xsl:key 构建节点集,然后多次重复使用该节点集。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多