Skip to main content
Solved

Using conditional output in XmlTemplater ?


lifalin2016
Contributor
Forum|alt.badge.img+29

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
Did this help you find an answer to your question?

3 replies

lifalin2016
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • March 26, 2020

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
Influencer
Forum|alt.badge.img+39
  • Influencer
  • 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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • March 26, 2020
ebygomm wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings