Skip to main content
Question

Loop for in XML Templater

  • November 17, 2017
  • 15 replies
  • 92 views

Forum|alt.badge.img

Hi,

I have a list of points point(0), point(1), point(2) ... and i will to retrieve them in a xml templater like this:

<listPoint>

for $i in (1 to {fme:get-attribute("_element_count")}) return {fme:get-attribute("point[$i]")}

</listPoint>

I don't succeed with this writing ...

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.

15 replies

takashi
Celebrity
  • 7843 replies
  • November 17, 2017
What values does the list contain, and what is your desired result?

 

 


Forum|alt.badge.img
  • Author
  • 32 replies
  • November 17, 2017
What values does the list contain, and what is your desired result?

 

 

 

The values contained inside point{} are floats.

 

the result desired is like this one :

 

<listPoint > 0,75534 0,4455 0,4532 0,67556 </listPoint >

 

 

Each value is separated by a space.

 

I have a counter to know how many points i have to write (_element_count).

 

But for the loop "for" i have a problem to write it in a Xml templater

takashi
Celebrity
  • 7843 replies
  • November 17, 2017

OK. You can easily convert the values contained by FME list attribute to XML list (space separated values) with the fme:get-list-attribute function. Try this expression.

<listPoint>{fme:get-list-attribute("point{}")}</listPoint>

Forum|alt.badge.img
  • Author
  • 32 replies
  • November 17, 2017

Hi

When i put this :

<listPoint>{for $i in (1 to {fme:get-attribute("_element_count")}) return $i}</listPoint>

it give me an error :

XMLTemplater_2(XMLTemplaterFactory): The following error occurred near line 2, column 32 of the query:

XMLTemplater_2(XMLTemplaterFactory): xs:string can not be promoted to parameter type xs:integer? of function to()

But when i put this :

<listPoint>{for $i in (1 to 10) return $i}</listPoint>

it gives me <listPoint>1 2 3 4 5 6 7 8 9 10 </listPoint>


Forum|alt.badge.img
  • Author
  • 32 replies
  • November 17, 2017

OK. You can easily convert the values contained by FME list attribute to XML list (space separated values) with the fme:get-list-attribute function. Try this expression.

<listPoint>{fme:get-list-attribute("point{}")}</listPoint>
Hi,

 

I have to test inside the list and extract by example the fifth element

 

 


takashi
Celebrity
  • 7843 replies
  • November 17, 2017

OK. You can easily convert the values contained by FME list attribute to XML list (space separated values) with the fme:get-list-attribute function. Try this expression.

<listPoint>{fme:get-list-attribute("point{}")}</listPoint>
Depending on what test is required. If you need to just extract the fifth element, you don't need any test.

 

<listPoint>{fme:get-attribute("point{4}")}</listPoint> 

Forum|alt.badge.img
  • Author
  • 32 replies
  • November 17, 2017
Depending on what test is required. If you need to just extract the fifth element, you don't need any test.

 

<listPoint>{fme:get-attribute("point{4}")}</listPoint> 
And if i have to test the position inside the list i put {fme:get-attribute("point{$i}")} ?

 


takashi
Celebrity
  • 7843 replies
  • November 17, 2017
Depending on what test is required. If you need to just extract the fifth element, you don't need any test.

 

<listPoint>{fme:get-attribute("point{4}")}</listPoint> 
Sorry, I cannot understand what you intend to realize. Could you please elaborate your actual requirement?

 

 


Forum|alt.badge.img
  • Author
  • 32 replies
  • November 17, 2017
Hi,

 

I have to test inside the list and extract by example the fifth element

 

 

When i put this line in my xml templater :

 

<listPoint> {for $i in (1 to xs:integer({fme:get-attribute("_element_count")})) return $i} </listPoint>

 

 

it output a xml fragment in 2 records :

 

<listPoint> 1 2 3 4 5 6 7 8 </listPoint>

 

<listPoint> 1 2 3 4 5 6 7 8 9 10 </listPoint>

 

 

In my two records, i have a list in each one, with 8 points for the first, 10 points for the second.

 

I have to made a test, depending on $i to verify that the point($i) is not negative. If it's the case, i have to extract this point($i), but i don't know the position in advance

 

 

 


takashi
Celebrity
  • 7843 replies
  • November 17, 2017
When i put this line in my xml templater :

 

<listPoint> {for $i in (1 to xs:integer({fme:get-attribute("_element_count")})) return $i} </listPoint>

 

 

it output a xml fragment in 2 records :

 

<listPoint> 1 2 3 4 5 6 7 8 </listPoint>

 

<listPoint> 1 2 3 4 5 6 7 8 9 10 </listPoint>

 

 

In my two records, i have a list in each one, with 8 points for the first, 10 points for the second.

 

I have to made a test, depending on $i to verify that the point($i) is not negative. If it's the case, i have to extract this point($i), but i don't know the position in advance

 

 

 

If you need to extract only positive values from the list, this expression might help you. No need to consider about their positions in the list.

 

<listPoint>{
    for $v in fme:get-list-attribute("point{}")
    where 0 < xs:double($v)
    return $v
}</listPoint> 

Forum|alt.badge.img
  • Author
  • 32 replies
  • November 18, 2017

Hi,

Is this good depending the test i have to do on the value of "i" in the list if i want to retrieve only certain values of points and output them in :

<listPoints>

if ( $i ==2 or $i ==5)

{fme:get-attribute(concat("point{", $i, "}"))}

</listPoints>


takashi
Celebrity
  • 7843 replies
  • November 18, 2017

Hi,

Is this good depending the test i have to do on the value of "i" in the list if i want to retrieve only certain values of points and output them in :

<listPoints>

if ( $i ==2 or $i ==5)

{fme:get-attribute(concat("point{", $i, "}"))}

</listPoints>

where does $i come from?

 

 


takashi
Celebrity
  • 7843 replies
  • November 18, 2017

Hi,

Is this good depending the test i have to do on the value of "i" in the list if i want to retrieve only certain values of points and output them in :

<listPoints>

if ( $i ==2 or  $i ==5)

{fme:get-attribute(concat("point{", $i, "}"))}

</listPoints>

possibly this expression generates your desired result?

 

<listPoints>{
for $p at $i in fme:get-list-attribute("point{}")
where $i eq 3 or $i eq 6  (: Edited :)
return $p
}</listPoints>

takashi
Celebrity
  • 7843 replies
  • November 18, 2017

Hi,

Is this good depending the test i have to do on the value of "i" in the list if i want to retrieve only certain values of points and output them in :

<listPoints>

if ( $i ==2 or  $i ==5)

{fme:get-attribute(concat("point{", $i, "}"))}

</listPoints>

Alternatively,

 

<listPoints>{
for $i in (2, 5)  (: Edited :)
return fme:get-attribute(fn:concat("point{",$i,"}"))
}</listPoints>
Note: The index for FME list elements is 0-based, but for XQuery sequence elements is 1-based.

takashi
Celebrity
  • 7843 replies
  • November 18, 2017
Alternatively,

 

<listPoints>{
for $i in (2, 5)  (: Edited :)
return fme:get-attribute(fn:concat("point{",$i,"}"))
}</listPoints>
Note: The index for FME list elements is 0-based, but for XQuery sequence elements is 1-based.
edited the expression examples above.