Skip to main content
Solved

create dynamic xml attribute names

  • December 21, 2018
  • 4 replies
  • 96 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

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.

4 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • 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
Celebrity
  • 7843 replies
  • 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
  • 12 replies
  • December 21, 2018

Works like a charm! Thanks @takashi


frro
Contributor
Forum|alt.badge.img+17
  • Contributor
  • 21 replies
  • March 2, 2021

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!