Skip to main content
Question

XMLTemplater with conditions

  • June 16, 2015
  • 3 replies
  • 97 views

jdh
Contributor
Forum|alt.badge.img+41
Hi all,

 

 

I'm working with the  XMLTemplater and would like to know if it's possible to conditionally process subtemplates.

 

 

ie if attr1 = "a" then {fme:process-template("X")} else {fme:process-template("Y")}
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

takashi
Celebrity
  • June 17, 2015
Hi,

 

 

I think you can use this syntax.

 

-----

 

{if(fme:get-attribute("attr1") eq "a") then {fme:process-template("X")} else {fme:process-template("Y")}}

 

-----

 

 

Takashi

jdh
Contributor
Forum|alt.badge.img+41
  • Author
  • Contributor
  • June 17, 2015
Thank you, that did exactly what I needed. Where did you find the syntax?

takashi
Celebrity
  • June 17, 2015
I found this description and example in the help doc of the XMLTemplater ;)

 

---

 

A common use case is to write out an XML element only if a feature attribute has a value. To do this, an if-then-else statement is used. The following example writes out the displayName element only if the feature contains a display_name attribute, and value of the attribute is not an empty string.

 

 

<road>

 

{ if( fme:has-attribute("display_name") and 

 

      not(fme:get-attribute("display_name") eq "") )

 

then <displayName>{fme:get-attribute("display_name")}</displayName>

 

else ()

 

}

 

</road>