[xquery-talk] Recursive string concatenation ?

Howard Katz howardk at fatdog.com
Wed Jun 22 13:13:00 PDT 2005


How about something like this? The serialization is just a wee bit off what
you've got (there are a few extra embedded spaces), but it's probably
tinkerable if it's important.

let $geom := <geometry type="POLYGON"> ... </geometry>
return
(
     $geom/@type/string(),
     "(",
          for $part in $geom/part
          return
          (
              "(", 
                   for $axis at $i in $part/* 
                   return
                   (
                         $axis/text(),

                         if ( $i mod 2 eq 0 )
                         then if ( $i ne count( $part/* ) )
                              then ","
                              else ( )
                         else " "
                   ),
              ")"
          ),
     ")"
)

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

Howard

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