Thnx Michael,

Found a tumbling example, and fiddled until I had this:

xquery version "3.0";

let $xml :=
    <Docs>
        <Doc>
            <P>blah blah blah<pg>1</pg>blah blah</P>
            <P>blah blah blah<pg>2</pg>blah blah</P>
        </Doc>
        <Doc>
            <P>blah blah blah<pg>3</pg>blah blah</P>
            <P>blah blah blah<pg>4</pg>blah blah</P>
        </Doc>
    </Docs>
return
    <Docs>{
        for $doc in $xml/Doc
        return
            <Doc>{
                for $P in $doc/P
                return
                    for tumbling window $w in $P/node()
                    start when true()
                    end next $e
                        when $e instance of element(pg)
                    return (
                        $w[self::pg],
                        <P>{
                            $w[not(self::pg)]
                        }</P>
                    )
            }</Doc>
    }</Docs>

Tested with http://try.zorba.io .. :)

Cheers,
Geert

> -----Oorspronkelijk bericht-----
> Van: Michael Kay [mailto:[email protected]]
> Verzonden: woensdag 20 november 2013 1:09
> Aan: Geert Josten
> CC: [email protected] Talk
> Onderwerp: Re: [xquery-talk] Group starting with in XQuery?
>
> If you're asking about XQuery 1.0, the answer is no, unless you regard
the
> solution using recursion as elegant.
>
> In XQuery 3.0 there are "tumbling windows" which give you the capability
of
> XSLT's group-starting-with, and a lot more besides.
>
> Michael Kay
> Saxonica
>
> On 19 Nov 2013, at 18:47, Geert Josten <[email protected]> wrote:
>
> > Just wondering, is there an elegant way of doing something like this
in
> > XQuery?
> >
> >    <xsl:stylesheet version="2.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> >             <xsl:output indent="yes"/>
> >             <xsl:strip-space elements="*"/>
> >
> >             <xsl:template match="@*|node()">
> >                     <xsl:copy>
> >                             <xsl:apply-templates select="@*|node()"/>
> >                     </xsl:copy>
> >             </xsl:template>
> >
> >             <xsl:template match="P">
> >                     <xsl:variable name="P" select="."/>
> >                     <xsl:for-each-group select="node()"
> > group-starting-with="pg">
> >                             <xsl:apply-templates select="self::pg"/>
> >                             <xsl:element name="{node-name($P)}">
> >                                     <xsl:apply-templates
> > select="$P/@*|current-group()[not(self::pg)]"/>
> >                             </xsl:element>
> >                     </xsl:for-each-group>
> >             </xsl:template>
> >
> >    </xsl:stylesheet>
> >
> > Example input:
> >
> > <Docs>
> >    <Doc>
> >        <P>blah blah blah<pg>1</pg>blah blah</P>
> >        <P>blah blah blah<pg>2</pg>blah blah</P>
> >    </Doc>
> >    <Doc>
> >        <P>blah blah blah<pg>3</pg>blah blah</P>
> >        <P>blah blah blah<pg>4</pg>blah blah</P>
> >    </Doc>
> > </Docs>
> >
> > Cheers,
> > Geert
> >
> > M.Sc. G.P.H. (Geert) Josten
> > Senior Developer
> >
> >
> > Dayon B.V.
> > Delftechpark 37b
> > 2628 XJ Delft
> > The Netherlands
> >
> > T +31 (0)88 26 82 570
> >
> > [email protected]
> > www.dayon.nl
> >
> > De informatie - verzonden in of met dit e-mailbericht - is afkomstig
van
> > Dayon BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
> > bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen.
> Aan
> > dit bericht kunnen geen rechten worden ontleend.
> > _______________________________________________
> > [email protected]
> > http://x-query.com/mailman/listinfo/talk
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to