[xquery-talk] Partitioning data with XQuery
Brian Maso
brian at blumenfeld-maso.com
Mon Apr 25 18:18:16 PDT 2005
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
>
>
>_______________________________________________
>talk at xquery.com
>http://xquery.com/mailman/listinfo/talk
More information about the talk
mailing list