Question

XMLTemplater with conditions


Badge +22
  • Contributor
  • 1961 replies
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")}

3 replies

Userlevel 2
Badge +17
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
Badge +22
Thank you, that did exactly what I needed. Where did you find the syntax?
Userlevel 2
Badge +17
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>

Reply