开发者

How to identify using xsl whether a node exists in my xml?

I have this xml

<game>
 <genre>
  <action>...</action>
  <racing>...</racing>
 <pri开发者_运维问答ce>
..
..
 </price>
</genre>
</game>

I want to check whether price node is present in the xml using xsl. how can I do that? if price node is present then call a particular template else call another template


You could simply call xsl:apply-templates with the match attribute set to the element name. If the element exists the template is called. It it does not exist, the template won't be called. If you are trying to build a if-else statement you could check the existence like this

<xsl:choose>
    <xsl:when test="boolean(price)">
        <!-- do something -->
    </xsl:when>
    <xsl:otherwise>
        <!-- do something else -->
    </xsl:otherwise>
</xsl:choose>

So you can check for existence of an element and react accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜