So I have this problem handling an XML file in my SAP ABAP-based software, with a Simple Transformation.
The file I receive have normally no empty tags like <test></test>
, but can happen sometimes that I receive some self closing tag like <test/>
.
This is an example of what I thought to use now. The first condition handles if the ref('test') is blank by skipping it. The second one takes the values if we have one.
<tt:cond check="initial(ref('test'))">
<tt:skip count="*" name="test"/>
</tt:cond>
<tt:cond check="not-initial(ref('test'))">
<test tt:value-ref="test"/>
</tt:cond>
The idea is: if we have this tag <test/>
we need to skip it, otherwise we need to assign the data. Now this is working for the first case, because it takes no data, but not for the second because it does not take the data.
Thanks in advanсe.
The XDM tree representations of <test></test>
and <test/>
are 100% identical, so there is no way an XSLT stylesheet can distinguish them or treat them differently. The idea of attaching different meanings to the two constructs is completely misguided: you can never be sure which representation an XML library will choose to use.
It is of course possible to distinguish an element that contains a value (such as <test>value</test>
) from one that is empty - but both the above examples represent empty elements and must be treated as equivalent.