Skip to main content
Solved

Using the XMLTemplator to dynamically populate an XML tag using a list values.

  • December 2, 2020
  • 7 replies
  • 39 views

andrewj74
Supporter
Forum|alt.badge.img+6

I am new to lists and xml in FME and having a bit of trouble. I am using the XMLTemplator to populate an XML tag using a list value. The following works as it should.

{

for $Contact_id in fme:get-list-attribute("Contact{}")

return <NRWContact>{$Contact_id}</NRWContact>

}

However I am also using a different list which has been produced using the list builder and the name of the list is appended on the end so can get it to recognise it to get the value.

{

for $ExcelColumnName_id in  {fme:get-list-attribute("list{}.ExcelColumnName")}

return

<Location>$ExcelColumnName_id</Location>

}

This just returns  “<Location>$ExcelColumnName_id</Location>” and not the value from the list  e.g <Location>Column B</Location>”. Hopefully it’s a simple tweak but I have not stumbled across it yet or found the same thing on the community.

Best answer by ebygomm

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 

Any better?

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v at $index in $values
let $n := $names[$index]
return
{    element {$n} {$v}}

The issue with the one posted earlier was that you obviously have values that are the same for different elements and that causes a problem as it's trying to use the value as a lookup. This avoids that

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.

7 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • December 2, 2020

It looks like you have some curly brackets in the wrong place, try

{
 
for $ExcelColumnName_id in  fme:get-list-attribute("list{}.ExcelColumnName")
 
return
 
<Location>{$ExcelColumnName_id}</Location>
 
}

 


andrewj74
Supporter
Forum|alt.badge.img+6
  • Author
  • Supporter
  • 45 replies
  • December 2, 2020

Thank you that did the job. i dont supose you colud help me further. Basically i am trying to dynamically template and XML document from a list.

list Example

list{0}.NewValue (encoded: UTF-8) 1

list{0}.XMLFieldName (encoded: UTF-16LE) Key

list{1}.NewValue (encoded: UTF-8) Yes

list{1}.XMLFieldName (encoded: UTF-16LE) Licenced

list{2}.NewValue (encoded: UTF-8) No

list{2}.XMLFieldName (encoded: UTF-16LE) External

list{3}.NewValue (encoded: UTF-8) Tim

list{3}.XMLFieldName (encoded: UTF-16LE) Name

desired output

<Key>1</Key><Licenced>Yes</Licenced><External>No</External><Name>Tim</Name>

 

i have been trying this in the xmltemplater but it fails with the following error (sequence of more than one item can not be cast to QName). I think it is failing as it cant handle the element being defined by a list value.

 

element

{

{fme:get-attribute("Licencing Dataset URI")}

}

{

for $NewValue_id in  fme:get-list-attribute("list{}.NewValue")

return

{$NewValue_id}

}

The other way i was thinking of tackling it is by the following whick also fails:

{

for $XMLFieldName_id in  fme:get-list-attribute("list{}.XMLFieldName")

for $NewValue_id in  fme:get-list-attribute("list{}.NewValue")

return

<{$XMLFieldName_id}>{$NewValue_id}</{$XMLFieldName_id}>

}

 

Sorry i am new to xquery but any pointer would be much appreciated.

   


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • December 2, 2020

Thank you that did the job. i dont supose you colud help me further. Basically i am trying to dynamically template and XML document from a list.

list Example

list{0}.NewValue (encoded: UTF-8) 1

list{0}.XMLFieldName (encoded: UTF-16LE) Key

list{1}.NewValue (encoded: UTF-8) Yes

list{1}.XMLFieldName (encoded: UTF-16LE) Licenced

list{2}.NewValue (encoded: UTF-8) No

list{2}.XMLFieldName (encoded: UTF-16LE) External

list{3}.NewValue (encoded: UTF-8) Tim

list{3}.XMLFieldName (encoded: UTF-16LE) Name

desired output

<Key>1</Key><Licenced>Yes</Licenced><External>No</External><Name>Tim</Name>

 

i have been trying this in the xmltemplater but it fails with the following error (sequence of more than one item can not be cast to QName). I think it is failing as it cant handle the element being defined by a list value. 

 

element

{

{fme:get-attribute("Licencing Dataset URI")}

}

{

for $NewValue_id in  fme:get-list-attribute("list{}.NewValue")

return

{$NewValue_id}

}

The other way i was thinking  of tackling it is by the following whick also fails:

{

for $XMLFieldName_id in  fme:get-list-attribute("list{}.XMLFieldName")

for $NewValue_id in  fme:get-list-attribute("list{}.NewValue")

return

<{$XMLFieldName_id}>{$NewValue_id}</{$XMLFieldName_id}>

}

 

Sorry i am new to xquery but any pointer would be much appreciated.

   

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 


andrewj74
Supporter
Forum|alt.badge.img+6
  • Author
  • Supporter
  • 45 replies
  • December 3, 2020

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 

thank you @ebygomm​ , think its getting there :) 

 

this fails as 

invalid argument type for function fn:boolean(): effective boolean value not defined for sequence of more than one item that starts with "xs:integer"

 

i have tried a few variations of the above be get similar errors. @Takashi Iijima​  are you able to advise?

 

Many thanks


andrewj74
Supporter
Forum|alt.badge.img+6
  • Author
  • Supporter
  • 45 replies
  • December 3, 2020

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 

i actually have a sequence in my list that can be used  which is the order that the xml elements are required in. i see the index of function starts at 1 so there would be a mismatch there..

 

list{0}.NewValue (encoded: UTF-8) DH1111

list{0}.sequenced (64 bit real) 0

list{0}.XMLFieldName (encoded: UTF-16LE) BusinessKey

 

list{1}.NewValue (encoded: UTF-8) 2222

list{1}.sequenced (64 bit real) 1

list{1}.XMLFieldName (encoded: UTF-16LE) LicenceID

 

list{2}.NewValue (encoded: UTF-8) n/a

list{2}.sequenced (64 bit real) 2

list{2}.XMLFieldName (encoded: UTF-16LE) SLicenceID


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • Best Answer
  • December 3, 2020

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 

Any better?

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v at $index in $values
let $n := $names[$index]
return
{    element {$n} {$v}}

The issue with the one posted earlier was that you obviously have values that are the same for different elements and that causes a problem as it's trying to use the value as a lookup. This avoids that


andrewj74
Supporter
Forum|alt.badge.img+6
  • Author
  • Supporter
  • 45 replies
  • December 4, 2020

I think you can do something like this, but I'm sure there are some other XML experts about who might be able to offer better advice, @Takashi Iijima​ 

let $values := fme:get-list-attribute('list{}.NewValue')
let $names := fme:get-list-attribute('list{}.XMLFieldName')
for $v in $values
let $n := $names[index-of($values,$v)]
return
{    element {$n} {$v}}

 

Thank you so much for your help - this worked a treat