Skip to main content
Question

Conditional statement in XML templater


Hello there,

 

I tried to comment on content of post https://knowledge.safe.com/questions/52852/seperate-a-single-field-values-into-two-xml-elemen.html# but for some obscure reason wasn't able to do so.

My question is a follow-up to the remark of @takashi in the other post concerning the tokenizer function:

Note: <bnr:foreignKey> elements would not be created if fme:get-attribute($fkey) was empty.

I ran into exactly that kind of situation. What would I do to avoid this?

I'm thinking about an if then else conditional statement but fear I am not capable of doing that. Assuming that $anykey is empty - would such a construct work?

{    
if ( fme:get-attribute($anykey) ne "" ) then    
{    
for $k in fn:tokenize(fme:get-attribute($anykey), '#')    
return    
     <mri:keyword>
              <gco:CharacterString>{$k}</gco:CharacterString>    
     </mri:keyword>
    }    
else    
{    
return    
     <mri:keyword>
              <gco:CharacterString/>   
     </mri:keyword>
    }
}

 

Unfortunately, this results in

(XMLTemplaterFactory): invalid expression: syntax error, unexpected ExprSingle (missing comma "," between expressions?)"

kind of errors, now matter how much I shuffle with both sorts of brackets.

Sorry, but I am totally new to this kind of syntax. Btw., is this some sort of XQuery language or a FME transformer specific adaptation?

Thanks for the help. It's much appreciated!

2 replies

takashi
Influencer
  • May 8, 2020

Hi @lmoeller, hopefully this expression works for you.

{    
    if ( fme:get-attribute($anykey) ne "" ) then
        for $k in fn:tokenize(fme:get-attribute($anykey), '#')    
        return    
        <mri:keyword>
            <gco:CharacterString>{$k}</gco:CharacterString>    
        </mri:keyword>
    else
        <mri:keyword>
            <gco:CharacterString/>   
        </mri:keyword>
}

  • Author
  • May 8, 2020
takashi wrote:

Hi @lmoeller, hopefully this expression works for you.

{    
    if ( fme:get-attribute($anykey) ne "" ) then
        for $k in fn:tokenize(fme:get-attribute($anykey), '#')    
        return    
        <mri:keyword>
            <gco:CharacterString>{$k}</gco:CharacterString>    
        </mri:keyword>
    else
        <mri:keyword>
            <gco:CharacterString/>   
        </mri:keyword>
}

Hi @takashi, oh yes it did. Works perfectly, and was not so far off my own trial. Thank you very much!


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