Check if XML node is empty

Posted by Vinit on Stack Overflow See other posts from Stack Overflow or by Vinit
Published on 2012-12-06T17:01:57Z Indexed on 2012/12/06 17:03 UTC
Read the original article Hit count: 176

Filed under:
|
|

I have a simple XML structure like

<main>
<node1><!-- comments --><!-- comments --></node1>
</main>

and this can have any number of sub-nodes or values like:

    <main>
    <node1><!-- comments --><!-- comments --><p>texttext text</p> 
more text <br/></node1>
    </main>

I want to check if the node is empty or not: I'm doing something like:

<xsl:if test="string-length(main/node1//text())&gt;0">

But it does not work as if there are multiple

tags, then string-length function will break coz of multiple arguments. Any help to solve this issue is really appreciated.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt