Skip to main content

Hi,

 

I'm trying to create a single xml template that can handle dynamic attribute names. The attribute name to be used is stored in another attribute. Please have a look at how i set up the xmltemplater to write the attributes names:

ROOT:

<root>

<a>head</a>

<feat>

{fme:process-features("SUB")}

</feat>

</root>

 

SUB:

<f>

<{fme:get-attribute("attr")}>{fme:get-attribute("value")}</{fme:get-attribute("attr")}>

</f>

 

Where 'attr' holds the attribute name and 'value' the value.

 

I get the following error:

The following error occurred near line 2, column 6 of the query:

 

invalid expression: syntax error, unexpected character "{"

An error occurred while parsing the 'SUB' sub-template

So clearly this is not the way to go. Is this possible in anyway or do I have to define specific SUBs (conditional) for every possible feature schema?

 

Thanks!

 

you have attributes in the tags?

Maybe create the template as a attribute and then add to the template?

@Pratsch

 

Should not the tags be created trough the template? Not via attributes?

I'm no expert on this, but referred to

https://knowledge.safe.com/articles/30940/xml-writing-with-xmltemplater.html


The computed element constructor might be what you are looking for. Try this SUB expression.

<f>{
    element {fme:get-attribute("attr")} {fme:get-attribute("value")}
}</f>

See here to learn more: 3.9.3.1 Computed Element Constructors -- XQuery 3.1: An XML Query Language


Works like a charm! Thanks @takashi


The computed element constructor might be what you are looking for. Try this SUB expression.

<f>{
    element {fme:get-attribute("attr")} {fme:get-attribute("value")}
}</f>

See here to learn more: 3.9.3.1 Computed Element Constructors -- XQuery 3.1: An XML Query Language

Wow!

Just wow! 

And thanks a lot!


Reply