Giulio Bambini
Giulio Bambini

Reputation: 4755

XSL select text in parent node with all children except one specific child node

I have a problem with XML and XSL, This is a portion of my XML document:

<node1>
    <node2>
        <node3>text inside node3 I don't want select</node3>
        text inside node2 that I want select
        <node4> text in node4 I want select</node4>
    </node2>
</node1>

node2 has some text inside and 2 children (node3 and node4), I need to select the text contained in node2 with the text in child node4 EXCEPT the one in node3. I also say that the structure of the node2 is not always the same,sometime it has some text only, or might have some text with node3 and/or node4. Also the order of the elements inside node2 may not always be the same but the result's order should be the same as that in the XML's order.

Thanks for the helps.

Upvotes: 0

Views: 1333

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

Starting from the node2 context, you could get all descendant text nodes except those that are inside a node3 using

.//text()[not(parent::node3)]

or more generally, if node3 might have child elements

<node2>
   keep this
   <node3>drop this <node7>drop this too</node7></node3>
   <node4>keep this</node4>
</node2>

then use ancestor:: instead ofparent::`

.//text()[not(ancestor::node3)]

Upvotes: 2

Related Questions