带标签名称的XSL

时间:2014-07-16 15:08:12

标签: xml xslt compare

我想使用XSL比较XML标记名称 示例:

<name>
  <item>
     TEST
  </item>
  <out>
     No item
  </out>
</name>

想知道我是否在<item>。 在XSL中(例如,我不知道该怎么做,但这是个主意):

<xsl:if test="name(.)==item">
  <xsl:value-of select="." />         <!-- it will print "TEST" -->
</xsl:if>

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码。

    <xsl:for-each select="//*">
        <xsl:if test="name(.)='item'">
            <xsl:value-of select="." />         
        </xsl:if>    
    </xsl:for-each>