[xquery-talk] Partitioning data with XQuery

Howard Katz howardk at fatdog.com
Mon Apr 25 17:29:31 PDT 2005


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




More information about the talk mailing list