Hi @mjoarder_pln, this is a simplified example.
Assuming that a list attribute called "attr{}.type" contains these values,
attr{0}.type = string
attr{1}.type = integer
attr{2}.type = double
and the number of elements ("_element_count" attribute) has been extracted by the ListElementCounter beforehand, this XML template (XQuery) expression creates the following XML fragment.
(: XMLTemplater Template Expression Example :)
<dataType>{
let $n := fme:get-attribute("_element_count") - 1
for $i in (0 to $n)
let $attr := "attr{"||$i||"}.type"
return
<CharacterString>{fme:get-attribute($attr)}</CharacterString>
}</dataType>
<?xml version="1.0" encoding="UTF-8"?>
<dataType>
<CharacterString>string</CharacterString>
<CharacterString>integer</CharacterString>
<CharacterString>double</CharacterString>
</dataType>
Hi @mjoarder_pln, this is a simplified example.
Assuming that a list attribute called "attr{}.type" contains these values,
attr{0}.type = string
attr{1}.type = integer
attr{2}.type = double
and the number of elements ("_element_count" attribute) has been extracted by the ListElementCounter beforehand, this XML template (XQuery) expression creates the following XML fragment.
(: XMLTemplater Template Expression Example :)
<dataType>{
let $n := fme:get-attribute("_element_count") - 1
for $i in (0 to $n)
let $attr := "attr{"||$i||"}.type"
return
<CharacterString>{fme:get-attribute($attr)}</CharacterString>
}</dataType>
<?xml version="1.0" encoding="UTF-8"?>
<dataType>
<CharacterString>string</CharacterString>
<CharacterString>integer</CharacterString>
<CharacterString>double</CharacterString>
</dataType>
Hi, i have applied your code example in my ROOT Template example, but it is not working, please see the following two screenshort. xml_1 and xml_2.

No data is inserting inside xml...

I want to see the values like this:

All the different column names and data types will come inside their own parent elements.
Thanks
Hi @mjoarder_pln, this is a simplified example.
Assuming that a list attribute called "attr{}.type" contains these values,
attr{0}.type = string
attr{1}.type = integer
attr{2}.type = double
and the number of elements ("_element_count" attribute) has been extracted by the ListElementCounter beforehand, this XML template (XQuery) expression creates the following XML fragment.
(: XMLTemplater Template Expression Example :)
<dataType>{
let $n := fme:get-attribute("_element_count") - 1
for $i in (0 to $n)
let $attr := "attr{"||$i||"}.type"
return
<CharacterString>{fme:get-attribute($attr)}</CharacterString>
}</dataType>
<?xml version="1.0" encoding="UTF-8"?>
<dataType>
<CharacterString>string</CharacterString>
<CharacterString>integer</CharacterString>
<CharacterString>double</CharacterString>
</dataType>
<bnr:MD_DataSchema>
<bnr:column>
<bnr:MD_Column>
<bnr:name>
{
let $n := fme:get-attribute("_element_count") - 1
for $i in (0 to $n)
let $attr := "eainfo.detailed.attr{"||$i||"}.attrlabl"
return
<gco:CharacterString>{fme:get-attribute($attr)}</gco:CharacterString>
}</bnr:name>
<bnr:description>
<gco:CharacterString/>
</bnr:description>
<bnr:dataType>{
let $n := fme:get-attribute("_element_count") - 1
for $i in (0 to $n)
let $attr1 := "eainfo.detailed.attr{"||$i||"}.attrtype"
return
<gco:CharacterString>{fme:get-attribute($attr1)}</gco:CharacterString>
}</bnr:dataType>
#
giving me the following error:
XMLTemplater(XMLTemplaterFactory): The following error occurred near line 62, column 17 of the query:
XMLTemplater(XMLTemplaterFactory): arithmetic operation not defined between types "xs:string" and "xs:integer"
A fatal error has occurred. Check the logfile above for details
|ERROR |
Perhaps are you using FME 2016? Since FME 2016 treats the value of "_element_count" as a string, you will have to explicitly convert it to integer in the expression like this.
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
My previous example was to repeat <CharacterString> element within a single parent element, but looks like it would not match your desired result. If you need to repeat <column> element which contains <name> and <type> elements as its descendants, this example might be better for you. Assuming that the input feature has a list attribute called "attr{}.name", "attr{}.type".
<parent>{
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
for $i in (0 to $n)
let $aname := "attr{"||$i||"}.name"
let $atype := "attr{"||$i||"}.type"
return
<column>
<name>
<CharacterString>{fme:get-attribute($aname)}</CharacterString>
</name>
<type>
<CharacterString>{fme:get-attribute($atype)}</CharacterString>
</type>
</column>
}</parent>
input:
attr{}.name contains "foo", "bar", and "foobar"
attr{}.type contains "string", "integer", and "double"
result:
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<column>
<name>
<CharacterString>foo</CharacterString>
</name>
<type>
<CharacterString>string</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>bar</CharacterString>
</name>
<type>
<CharacterString>integer</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>foobar</CharacterString>
</name>
<type>
<CharacterString>double</CharacterString>
</type>
</column>
</parent>
Perhaps are you using FME 2016? Since FME 2016 treats the value of "_element_count" as a string, you will have to explicitly convert it to integer in the expression like this.
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
My previous example was to repeat <CharacterString> element within a single parent element, but looks like it would not match your desired result. If you need to repeat <column> element which contains <name> and <type> elements as its descendants, this example might be better for you. Assuming that the input feature has a list attribute called "attr{}.name", "attr{}.type".
<parent>{
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
for $i in (0 to $n)
let $aname := "attr{"||$i||"}.name"
let $atype := "attr{"||$i||"}.type"
return
<column>
<name>
<CharacterString>{fme:get-attribute($aname)}</CharacterString>
</name>
<type>
<CharacterString>{fme:get-attribute($atype)}</CharacterString>
</type>
</column>
}</parent>
input:
attr{}.name contains "foo", "bar", and "foobar"
attr{}.type contains "string", "integer", and "double"
result:
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<column>
<name>
<CharacterString>foo</CharacterString>
</name>
<type>
<CharacterString>string</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>bar</CharacterString>
</name>
<type>
<CharacterString>integer</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>foobar</CharacterString>
</name>
<type>
<CharacterString>double</CharacterString>
</type>
</column>
</parent>
This expression generates the same result.
<parent>{
let $names := fme:get-list-attribute("attr{}.name")
let $types := fme:get-list-attribute("attr{}.type")
for $i in (1 to fn:count($names))
return
<column>
<name>
<CharacterString>{$names[$i]}</CharacterString>
</name>
<type>
<CharacterString>{$types[$i]}</CharacterString>
</type>
</column>
}</parent>
Perhaps are you using FME 2016? Since FME 2016 treats the value of "_element_count" as a string, you will have to explicitly convert it to integer in the expression like this.
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
My previous example was to repeat <CharacterString> element within a single parent element, but looks like it would not match your desired result. If you need to repeat <column> element which contains <name> and <type> elements as its descendants, this example might be better for you. Assuming that the input feature has a list attribute called "attr{}.name", "attr{}.type".
<parent>{
let $n := xs:integer(fme:get-attribute("_element_count")) - 1
for $i in (0 to $n)
let $aname := "attr{"||$i||"}.name"
let $atype := "attr{"||$i||"}.type"
return
<column>
<name>
<CharacterString>{fme:get-attribute($aname)}</CharacterString>
</name>
<type>
<CharacterString>{fme:get-attribute($atype)}</CharacterString>
</type>
</column>
}</parent>
input:
attr{}.name contains "foo", "bar", and "foobar"
attr{}.type contains "string", "integer", and "double"
result:
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<column>
<name>
<CharacterString>foo</CharacterString>
</name>
<type>
<CharacterString>string</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>bar</CharacterString>
</name>
<type>
<CharacterString>integer</CharacterString>
</type>
</column>
<column>
<name>
<CharacterString>foobar</CharacterString>
</name>
<type>
<CharacterString>double</CharacterString>
</type>
</column>
</parent>
Hi, takashi , it works! Thanks a lot ...