0

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 <node1> is empty or not:
Condition: the node can still have comments in it and it should be still marked as empty 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 <p> tags, then string-length function will break because of multiple arguments.

Any help to solve this issue is really appreciated.

2
  • Describe more precisely what you are trying to do. Best is an XSLT, XML source and desired result. Commented Dec 6, 2012 at 17:07
  • @ThomasW: I want to check if <node1> is empty or not. Condition: it can still have comments inside it. If it has anything other than comment then if condition should fail. Commented Dec 6, 2012 at 17:10

1 Answer 1

1

<xsl:template match="main/node1[* | text()[normalize-space()]"> matches those node1 elements that have at least one element child node or one text child node with content other than whitespace. So the condition node1[* | text()[normalize-space()] might be what you are looking for as it ignores comment node (and processing instruction nodes).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.