[xquery-talk] Partitioning data with XQuery

Howard Katz howardk at fatdog.com
Mon Apr 25 22:59:12 PDT 2005


Hi Michael,
You'll have to humiliate everybody who ever tried to simulate structure
using an HTML tag set. In this case the weirdness of the design originated
in the dictates of HTML and actually doesn't look so crazy in that domain.
See my response to Brian. I imagine XQuery used in screen-scraping is going
to encounter a lot of krufty "designs" like this.
Howard

 > -----Original Message-----
 > From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com]On Behalf
 > Of Michael Rys
 > Sent: Monday, April 25, 2005 6:08 PM
 > To: howardk at fatdog.com; xquery-talk
 > Subject: RE: [xquery-talk] Partitioning data with XQuery
 >
 >
 > Here is a generic solution:
 >
 > 1. Take the person that originally design the input format and publicly
 > humiliate him or her. This is really bad design.
 >
 > 2. Repeat step 1 a hundred times.
 >
 > 3. Then use the following XQuery expression to perform the transform:
 >
 > for $r in /record/subRecordStart
 > return
 >   <record>{
 >     /record/node()[(. << (/record/subRecordStart[. >> $r])[1] and . >>
 > $r)
 >         or ($r is (/record/subRecordStart)[last()] and . >> $r)]
 >   }</record>
 >
 > HTH
 > Michael
 >
 > > -----Original Message-----
 > > From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On
 > Behalf
 > > Of Howard Katz
 > > Sent: Monday, April 25, 2005 4:30 PM
 > > To: xquery-talk
 > > Subject: [xquery-talk] Partitioning data with XQuery
 > >
 > > 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
 >
 > _______________________________________________
 > talk at xquery.com
 > http://xquery.com/mailman/listinfo/talk
 >




More information about the talk mailing list