[xquery-talk] Group starting with in XQuery?

David Lee dlee at calldei.com
Tue Nov 19 17:31:45 PST 2013


Everything in XQuery is elegant.


----------------------------------------
David A. Lee
dlee at calldei.com
http://www.xmlsh.org

-----Original Message-----
From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of Michael Kay
Sent: Tuesday, November 19, 2013 7:09 PM
To: Geert Josten
Cc: talk at x-query.com Talk
Subject: 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 <geert.josten at dayon.nl> 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
> 
> geert.josten at dayon.nl
> 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.
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk


_______________________________________________
talk at x-query.com
http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list