# [xquery-talk] Recursive string concatenation ?

Michael Kay mhk at mhk.me.uk
Wed Jun 22 23:37:16 PDT 2005

that doesn't),

Problem 1:

test.xq:

let \$in :=
document {
<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> }
return
\$in/geometry/
concat(@type, '((',
string-join(part/
string-join(
for \$x in X
return concat(\$x, ' ', \$x/following-sibling::Y[1]),
','),
')('),
'))')

java net.sf.saxon.Query test.xq !method=text

POLYGON((1 2,3 4,5 6)(7 8,9 10,11 12))

Pure XPath 2.0, as it happens - no XQuery needed. (And no recursion)

Problem 2:

change "for \$x in X" to "for \$x in (X, X[1])"

output:

POLYGON((1 2,3 4,5 6,1 2)(7 8,9 10,11 12,7 8))

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Pierrick Brihaye
> Sent: 22 June 2005 17:48
> 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
>