Skip to main content

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 ...

What values does the list contain, and what is your desired result?

 

 


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

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

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>


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

 

 


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> 

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}")} ?

 


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?

 

 


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

 

 

 


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> 

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>


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?

 

 


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>

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.
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.

 

 


Reply