[xquery-talk] Recursive string concatenation ?
Peter Coppens
Peter.Coppens at datadirect.com
Wed Jun 22 14:48:40 PDT 2005
Not very readable, but it seems to work on the 'sample input' provided.
declare function local:p($g as node()) as xs:string {
fn:concat($g/@type,'(',fn:string-join($g/part/concat('(',fn:string-join(
./X/concat(./text(),'
',./following-sibling::Y[1]/text()),','),',',fn:string-join(./X[1]/conca
t(./text(),' ',./following-sibling::Y[1]/text()),','),')'),''),')')
};
local:p(
<geometry type="POLYGON">
<part>
<X>1</X>
<Y>2</Y>
<X>3</X>
<Y>4</Y>
<X>5</X>
<Y>6</Y>
</part>
<part>
<X>7</X>
<Y>8</Y>
<X>9</X>
<Y>10</Y>
<X>11</X>
<Y>12</Y>
</part>
</geometry>)
Hope this helps,
Peter
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Pierrick Brihaye
> Sent: Wednesday, June 22, 2005 6:48 PM
> To: talk at xquery.com
> Subject: [xquery-talk] Recursive string concatenation ?
>
> Hi,
>
> Given the following XML :
>
> <geometry type="POLYGON">
> <part>
> <X>1</X>
> <Y>2</Y>
> <X>3</X>
> <Y>4</Y>
> <X>5</X>
> <Y>6</Y>
> </part>
> <part>
> <X>7</X>
> <Y>8</Y>
> <X>9</X>
> <Y>10</Y>
> <X>11</X>
> <Y>12</Y>
> </part>
> </geometry>
>
> ... I wonder how I could write an XQuery function to get this string
> result :
>
> POLYGON((1 2,3 4,5 6)(7 8,9 10,11 12))
> or, better :
> POLYGON((1 2,3 4,5 6,1 2)(7 8,9 10,11 12,7 8))
>
> Any hints ?
>
> Cheers,
>
> p.b.
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
>
More information about the talk
mailing list