Skip to main content
Solved

create dynamic xml attribute names

  • December 21, 2018
  • 4 replies
  • 76 views

pratsch
Forum|alt.badge.img

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!

 

Best answer by 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

View original
Did this help you find an answer to your question?

4 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • December 21, 2018

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


takashi
Influencer
  • Best Answer
  • December 21, 2018

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


pratsch
Forum|alt.badge.img
  • Author
  • December 21, 2018

Works like a charm! Thanks @takashi


frro
Contributor
Forum|alt.badge.img+15
  • Contributor
  • March 2, 2021
takashi wrote:

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!


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