Skip to main content
Solved

Using conditional output in XmlTemplater ?


lifalin2016
Influencer
Forum|alt.badge.img+41

Hi list.

I'm currently trying to generate a composite XML using XmlTemplater.

One of the details is that tags without text value must not be output at all.

I tried to utilize the following expression (from the help page):

{ if( {fme:has-attribute("mailadresse")} )
then <ler:mailadresse>{fme:get-attribute("mailadresse")}</ler:mailadresse>
else ()}

My expectation (for "else") is that output is only generated if an attribute value is present.

Much to my surprise, "<ler:mailadresse/>" is output instead, even though the attribute value in question is <null>.

Can anyone share how to tweak the expression, so "else" produces absolutely no output ?

And yes, the presence of the "else" part seems to be mandatory.

Using 2020.0

Best answer by ebygomm

I think has attribute tests for if the attribute exists, i.e. not missing. If if is null or empty the attribute still exists and you have to include the test for a value. You could use a nullattributemapper beforehand instead to map empties and nulls to missing

View original
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

lifalin2016
Influencer
Forum|alt.badge.img+41

Hmm. It seems I needed to add the >> not(fme:get-attribute() eq "") << part as well, to have the <null> values fails the condition.

Seems a little quirky to me.


ebygomm
Evangelist
Forum|alt.badge.img+54
  • Evangelist
  • Best Answer
  • March 26, 2020

I think has attribute tests for if the attribute exists, i.e. not missing. If if is null or empty the attribute still exists and you have to include the test for a value. You could use a nullattributemapper beforehand instead to map empties and nulls to missing


lifalin2016
Influencer
Forum|alt.badge.img+41

I think has attribute tests for if the attribute exists, i.e. not missing. If if is null or empty the attribute still exists and you have to include the test for a value. You could use a nullattributemapper beforehand instead to map empties and nulls to missing

Yeah, came to the same conclusion when I tested some more. Thanks for answering anyway.