XSLT使用local-name()比较XML

时间:2010-03-07 11:46:44

标签: xml xslt

我是新的XSLT,但我希望能够与使用XSL的XML进行比较。 可能会更改节点的问题,因此我需要使用lacal-name()。

但我似乎无法做到这一点。 请检查以下内容并帮助我。

    <xsl:output method="xml" indent="yes"/>
  <xsl:param name="Doc1" select="Root/items/*" />
  <xsl:param name="Doc2" select="Root/items/*" />

  <xsl:variable name="Second" select="$Doc2/Root/items/*"/>

  <xsl:template match="/">
    <xsl:apply-templates select="$Doc1/*"/>
  </xsl:template>

  <xsl:template match="items">
    <Root>
    <xsl:for-each select="item">
      <xsl:variable name="Names" select="$Second/local-name()"/>
      <xsl:choose>
        <xsl:when test="$Names!=$Names">
          <xsl:value-of select="$Second/current()"/>
         </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="current()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    </Root>
  </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

不知道这是 问题,但赫拉至少有几个......

<xsl:param name="Doc2" select="Root/items/*" />

路径为Root/items/*

<xsl:variable name="Second" select="$Doc2/Root/items/*"/>

路径为Root/items/*/Root/items/*

<xsl:variable name="Names" select="$Second/local-name()"/>

现在你要说节点集中的每个项目的本地名称为``Root / items / / Root / items / `。

然后在

<xsl:when test="$Names!=$Names">

将检索到的名称列表与检索到的名称列表进行比较,并在这些值(相同)不相等的情况下执行某些操作。

要进一步回答您的问题,了解原始文档的外观会很有帮助。此外,您如何将节点传递到xlt?并且,如果元素的名称在每个文档中都不是唯一的,Root/items/*/local-name()确实会返回一个节点列表而不是一个单个节点(实际上你说的是给我{{1}下所有项目的本地名称})。

相关问题