I am new to XSLT and I followed the article below to implement my requirement. My requirement is to remove the parent node completely if a condition in the child node is met. Same as the article below.
deleting the parent node if child node is not present in xml using xslt
In reference to the example in the above article, I was able to remove the content under <car>
. However, my source xml has a twist. The twist is that it has a namespace.
For example:
source xml
<car xmlns="urn:test:v2xml">
.....
</car>
output xml:
<car/>
In my implementation, the result was an empty car node in my XML output. I am expecting the car node to be completed removed but no matter what I tried, the empty car node remains in the output xml.
Is there a way to completely remove that car node? I suspect that my namespace has something to do with it because without the namespace, it works and the tag is completely removed.
I was able to achieve what I wanted by chaining a second transformation process to remove the empty node. It's called multi-pass. Thus, in a single XSLT stylesheet, the first output was created with the empty node. Then in a second transformation in the same stylesheet, a search is made to remove the empty nodes. The final output provided the cleaned result. Example of two-pass transformation is here:
Two phase processing: Do not output empty tags from phase-1 XSLT 2.0 processing
You'll need to specify the namespace for
car
, taking care of whether you want to squelchcar
orCar
: