Thse is my xml
<element1> <subel1/> </element1> <element2> <subel2/> </element2> <element3> <subel3/> </element3> <criteria> <subel3/> </criteria>
how i can select all node with xsl that not are in criteria subnodes?
like these
<subel1/> <subel2/>
How is this done?
If the xml is formated as:
<element1>
<el> subel1 </el>
</element1>
<element2>
<el> subel2
</el>
</element2>
<element3>
<el> subel3 </el>
</element3>
<criteria>
<subel3/>
</criteria>
This transformation:
when applied on this XML document (based on the provided XML fragment, but wrapped the XML fragmentwithin a top element and added one more child to
criteriato make the problem less trivial):produces the wanted result (no other published answer at the time of writing this produces a correct result):
Step-by-step explanation:
The XPath expression:
/*/*[not(self::criteria)]/*selects every element whose parent is an element not named
"criteria"and which is a child of the top element of the document.<xsl:for-each>instruction we check if the current node has a name that is not one of the names of any children ofcriteriaand only copy such a node:self::node()[not(/*/criteria/*[name()=name(current())])]This XPath expression selects the current node (
self::node()) only if there doesn’t exist a child of/*/criteria, whose name is the same as the name of the current node (not(/*/criteria/*[name()=name(current())])).Here we use the fact that
not(someNode-Set)isfalse()only if the nodesetsomeNode-Setis empty.