Hi,
I was wondering if there is a way in which it is possible to differentiate between an Empty String and a <null> value when using (XQuery in) the XMLTemplator.
As an example I created 4 features. The first having a regular string value, and the latter 3 having 'no value', but each a different type of 'no value' (empty string, <null>, <missing>);
When creating a dummyXML, I would like to be able to be able to handle/create a different 'b' element, based on the value of the attribute b. Let's say I have two fixed elements 'a' and 'c', and I want my dynamic 'b' element to be placed in between these two, then iterating over the different 4 features I would like to obtain the following result;
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
<b>value_b</b>
<c>value_c</c>
</dummyXML>
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
<b/>
<c>value_c</c>
</dummyXML>
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
<b xsi:nil="true" nilReason="unknown"/>
<c>value_c</c>
</dummyXML>
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
<c>value_c</c>
</dummyXML>
To do so, I used the following XML/XQuery statement in my XMLTemplator;
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
{
if ( not(fme:has-attribute("b")) )
then ()
else if ( not(fme:get-attribute("b") = "" or fme:get-attribute("b") = "NULL") )
then (<b>{fme:get-attribute("b")}</b>)
else if ( fme:get-attribute("b") = "" )
then (<b/>)
else if ( fme:get-attribute("b") = "NULL" )
then (<b xsi:nil="true" nilReason="unknown"/>)
else ()
}
<c>value_c</c>
</dummyXML>
But as you can see this only works if I convert my <null> value first to a string value 'NULL'. I'm wondering if there is maybe also an XQuery function that is able to determine if a value is null. I would have hoped for something similar to fme:has-attribute(), but then e.g. fme:attribute-is-null() or something, but I don't see one in the XQuery Functions documentation page of Safe.
Maybe there is some other native (non fme) XQuery function that can achieve this?
Kind regards,
Thijs
ps. see also attached sample workspace.