How to remove the processing instruction tag in xml using XQuery ?
Sample XML:
<a>
<text><?test id="1" loc="start"?><b type="bold">1. </b>
Security or protection <?test id="1" loc=="end"?><?test id="1" loc="start"?><b type="bold">2.
</b> Analyse.
<?test id="1" loc="end"?></text>
</a>
Expected output :
<a>
<text><b type="bold">1. </b> Security or protection <b type="bold">2.
</b> Analyse.</text>
</a>
Kindly help to removing PI tags.
Something like this should work:
xquery version "1.0-ml";
declare function local:suppress-pi($nodes) {
for $node in $nodes
return
typeswitch ($node)
case element() return
element { fn:node-name($node) } {
$node/@*,
local:suppress-pi($node/node())
}
case processing-instruction() return ()
default return $node
};
local:suppress-pi(<a>
<text><?test id="1" loc="start"?><b type="bold">1. </b>
Security or protection <?test id="1" loc=="end"?><?test id="1" loc="start"?><b type="bold">2.
</b> Analyse.
<?test id="1" loc="end"?></text>
</a>)
HTH!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With