2010-03-07 24 views
0

我是新的XSLT,但我希望能够使用XSL与XML进行比较。 问题的节点可能会改变,所以我需要使用lacal-name()。使用本地名称比较XML的XSLT()

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

<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

你能告诉我们源XML和你想要的输出? –

回答

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

有你现在说的节点集合``根/项目/ /根/项目/`每个项目获得本地名称。

然后在

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

你比较名称名称的检索表的检索列表,并做一些事情,如果这些值(这是相同的)应该是不相等的。

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