[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Partitioning data with XQuery

Brian Maso brian at blumenfeld-maso.com
Mon Apr 25 18:18:16 PDT 2005


maso.com
I haven't this exact code it, but the use of the "<<" and ">>" operators to 
compare relative positions of children in document order can be used to get 
the job done.

for each $record in $records
let $firstSubRecord := $record/subRecordStart[1],
     $secondSubRecord := $record/subRecordStart[2]
return
   <record>
   {
     $record/(* | text())[. >> $firstSubRecord and . << $secondSubRecord])
   }
   </record>

   <record>
   {
     $record/(* | text())[. >> $secondSubRecord]
   }
   </record>

Is this a translation of a traditional flatfile in to XML or something? Use 
of empty elements to delimit sections is a little strange, and that's the 
only kind of soruce I can imagine this kind of thing coming from.

Brian Maso

At 04:29 PM 4/25/2005, Howard Katz wrote:

>I need to repartition some XML data using XQuery, and I can't see how to do
>it. The basic data looks something like this:
>
><record>
>      <subRecordStart/>          (: marks start of new sub-record :)
>      some pcdata_1
>      <someElement_1/>
>      some more pcdata_1
>      <anotherElement_1/>
>      ... etc
>
>      <subRecordStart/>          (: marks start of new sub-record :)
>      some more pc data_2
>      <yetAnotherElement_2/>
>      yet some more pc data_2
>      <andYetAnotherElement_2/>
>      ... etc
></record>
>...
>
>The contents of each <record> consists of exactly two <subRecordStart/>
>elements, plus some undetermined mixture of elements and text nodes. Each
><record> needs to be replaced by two new <record> elements formed by
>partioning its contents into two parts. The place where each new record is
>to begin is indicated by a <subRecordStart/> marker, with the first
><subRecordStart/> marker being the first element child of <record>. Other
>than that and the fact there are exactly two markers per record, the rest of
>the contents are not known in advance.
>
>On application of the appropriate XQuery, the single record above would be
>replaced by the following two:
>
><record>
>      some pcdata_1
>      <someElement_1/>
>      some more pcdata_1
>      <anotherElement_1/>
></record>
><record>
>      some more pc data_2
>      <yetAnotherElement_2/>
>      yet some more pc data_2
>      <andYetAnotherElement_2/>
></record>
>
>This doesn't look difficult, but a solution eludes me. Can somebody suggest
>an XQuery that would be able to do this?
>TIA,
>Howard
>
>
>_______________________________________________
>http://xquery.com/mailman/listinfo/talk
>http://xquery.com/mailman/listinfo/talk



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.