Here is my problem... I need to select everything in an entire xml document, but leaving out one tag. Unfortunately, this tag can vary in depth.
Using the following code sample, I would like to remove all <crud>
, <crud2>
and <...>
(etc.) elements. <crud>
could have more children, but I don't want them anyways.
<body>
<h2/>
<crud>
<crud2/>
<...>
</crud>
<div>
<p> </p>
</div>
<div>
<p>
</p>
<crud>
<crud2/>
<...>
</crud>
</div>
</body>
I've tried a few methods.
let $body := "the xml sample"
return $body/*[fn:not(descendant-or-self::crud)]
This method takes to much. It removes the entire <div>
block that contains crud, but I need the <div>
and the <p>
that is included.
All other methods seem to only remove the direct <crud>
children of <body>
or it removes the container as well.
So, I essentially need a method that reaches in every element and removes all the <crud>
without taking anything else.
The final XML should look like this:
<body>
<h2/>
<div>
<p> </p>
</div>
<div>
<p>
</p>
</div>
</body>
I greatly appreciate any and all help.