I have the following XML
<ns0:Root xmlns:ns0="http://Map_Sample.Input_Schema">
<Number1>
</Number1>
<Number2>11</Number2>
<Number3>12</Number3>
</ns0:Root>
In this case I am getting ENTER
or \r\n
for Number1
. I want to write some XSLT to check if a node contains ENTER
or \r\n
and then replace it <Number1 />
.
Can anyone help me to write the XSLT for this?
There are different possible definitions of what an "empty element" could mean.
Let's define an empty element as one that doesn't have any element nodes children and whose string value is the empty string, or consists only of white space characters (' ', CR, NL).
Then to check if a given element is empty, use:
This assumes that the element is the context node when the XPath expression is evaluated.
You haven't specified with what this text node should be replaced, so in this solution I am assuming the text node should be replaced with the empty string (deleted):
When this transformation is applied on the provided XML document:
the wanted result is produced:
Try the following:
Explanation: skip output for elements where the (full descendants') text content is pure whitespace.