How to exclude specific descendants of a node? In this direction, the expression *[not(self::nodetag)] seems just to discriminate at a child level of the node, accepting all other descedants in the returned node set. I want a expression to select all under div but those nodes that are not a, see example below. The tree structure must remain the same.
The approach poste by @Dimitri Novatchev seems to be right but not for HAP implementation:
Using this example document:
<div>
<span>
<a>lala</a>
</span>
</div>
The HAP would return the following structure with his suggested expression /div/descendant::node()[not(self::a)]
<div>
<span>
<a>lala</a>
</span>
</div>
<span>
<a>lala</a>
</span>
If there would be another tag other than a nested on span, it would also return it as a separte tree, any one know about this strange behavior? Is it a HAP bug?
Thanks
Use:
This selects any descendant of the top element
divthat (the descendant) is not ana.XSLT – based verification:
When this transformation is applied on the provided XML document:
the XPath expression is evaluated and all selected nodes are output with proper formatting to make them well-visible:
As we can see, 6 nodes are selected — one
spanelement, four whitespace-only text nodes and one non-whitespace-only text node — and none of them is ana.Update:
In a comment the OP has clarified that he actually wants the XML document to be transformed into another, in which any
adescendant of adivis omitted.Here is one such transformation:
When this transformation is applied on the same XML document (above), the (wwhat I guess is) wanted result is produced:
If we want to produce only the descendants of any
divthat has anadescendant, then we need almost the same transformation:The result of this applied to the same XML document as above is: