[xquery-talk] Re: Recursive string concatenation ?
Pierrick Brihaye
pierrick.brihaye at free.fr
Wed Jun 22 23:37:05 PDT 2005
Peter Coppens a écrit :
> Not very readable, but it seems to work on the 'sample input' provided.
Yoho !!!! Applied to my actual example :
<GEOREF>
<ZONE>Lambert0</ZONE>
<COOR>
<X>297839,448770947 X</X>
<Y>2404764,15926586 Y</Y>
</COOR>
<ETENDUE TYPE="POLYGONE">
<COORM>
<X>297268 X</X>
<Y>2408434 Y</Y>
<X>297283 X</X>
<Y>2408419 Y</Y>
<X>297324 X</X>
<Y>2408319 Y</Y>
<X>297259 X</X>
<Y>2408344 Y</Y>
</COORM>
</ETENDUE>
</GEOREF>
and refactored as such :
declare namespace local = "urn:my-functions";
declare function local:p($g as node()) as xs:string {
let $type :=
if ($g/ETENDUE/@TYPE = 'POLYGONE') then
'POLYGON'
else if ($g/ETENDUE/@TYPE = 'POLYLIGNE') then
'MULTILINESTRING'
else
'other'
return
fn:concat(
$type,
'(',
fn:string-join(
$g/ETENDUE/COORM/concat(
'(',
fn:string-join(
./X/concat(
normalize-space(substring-before(., "X")),
' ',
normalize-space(substring-before(./following-sibling::Y[1], "Y"))
),
' , '
),
' , ',
./X[1]/concat(
normalize-space(substring-before(., "X")),
' ',
normalize-space(substring-before(./following-sibling::Y[1],
"Y"))
),
')'
),
' '
),
')'
)
};
for $geometry in //GEOREF
return
local:p($geometry)
I get :
POLYGON((297268 2408434 , 297283 2408419 , 297324 2408319 , 297259
2408344 , 297268 2408434))
Well... I have to investigate about string-join.
Thank you !
p.b.
More information about the talk
mailing list