开发者

How to check XML has a node or it is an empty file using XSLT?

Please help on this issue.

I want to check an XML contains a node or not [OR] it is an empty file using XSLT.

My XML is:

<mynode>
   <node1>testing</node1>
</mynode>

I want to write XSLT code something like this:

<xsl:choose>
  <xsl:when test="document('')/mynode">
    file is empty
  </xsl:when>
  &开发者_运维问答lt;xsl:otherwise>
    file has nodes
  </xsl:otherwise>
</xsl:choose>

Please any one can help me on this.....


If the file doesn't contain an element, then it is not an XML file, and XML parsing will therefore fail. Different XSLT 1.0 processors react differently to this (as permitted by the spec). In XSLT 2.0 you can use doc-available() to protect yourself, but this is not available in 1.0. In fact, there's nothing you can do about this in 1.0 without knowing details of your particular XSLT processor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜