[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Recursive positional grouping (was xsl digest...)

Subject: RE: Recursive positional grouping (was xsl digest...)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 5 Apr 2007 09:08:21 +0100
RE:  Recursive positional grouping (was xsl digest...)
Within xsl:for-each-group, current-group() selects all the nodes in the
group being processed, whereas "." selects only the first node in that
group. Writing "." is equivalent to writing current-group()[1].

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: john jacks [mailto:john.jacks@xxxxxxxxxxx] 
> Sent: 05 April 2007 08:28
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Recursive positional grouping (was xsl digest...)
> 
> Thanks Michael.
> (As Abel pointed out, I'm replying to the digest since that's 
> what I receive).
> 
> This works nicely. I don't understand the difference between 
> <xsl:apply-templates select="."/>
> 
> and
> 
> <xsl:apply-templates select="current-group()"/>
> 
> within the xsl:for-each-group instruction.
> 
> The book says ' use current-group() is sometimes better 
> especially if the group includes elements of different types' 
> which this example does.
> 
> How can I understand the difference please?
> 
> JJ
> 
> 
> From: "Michael Kay" <mike@xxxxxxxxxxxx>
> Subject: RE:  Recursive positional grouping (was xsl digest...)
> Message-ID: <009e01c7769e$d165d290$6401a8c0@turtle>
> 
> I think your problem is that 
> 
> <xsl:apply-templates select="current-group()"/>
> 
> is processing all the elements in a group, not only the 
> next-level headings
> - so the paragraphs are output at every level.
> 
> I think this kind of recursive grouping works best if you use 
> a named template that is passed the contents of a group as a 
> parameter. Try something like this:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet 
> version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   xmlns:xs="http://www.w3.org/2001/XMLSchema";>
> <xsl:output indent="yes"/>
> 
> <xsl:template name="group">
>   <xsl:param name="pop" as="element()*"/>
>   <xsl:param name="level" as="xs:integer" />
>   <xsl:variable name="key" as="xs:string" select="concat('h', 
> $level)"/>
>     <xsl:for-each-group select="$pop" 
> group-starting-with="*[name() eq $key]">
>       <xsl:choose>
>         <xsl:when test="starts-with(name(.), 'h')">
>           <section level="{$level}">     
>             <head><xsl:apply-templates 
> select="current-group()[1]"/></head>
>             <xsl:call-template name="group">
>               <xsl:with-param name="pop" 
> select="remove(current-group(), 1)"/>
>               <xsl:with-param name="level" select="$level + 1"/>
>             </xsl:call-template>
>           </section> 
>         </xsl:when>
>         <xsl:otherwise>
>           <xsl:copy-of select="current-group()"/>
>         </xsl:otherwise>
>       </xsl:choose>    
>     </xsl:for-each-group>
> </xsl:template>
> 
> <xsl:template match="/">
>   <doc>
>     <xsl:call-template name="group">
>       <xsl:with-param name="pop" select="body/*"/>
>       <xsl:with-param name="level" select="1"/>
>     </xsl:call-template>
>   </doc>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 
> 
> 
> 
> 	
> 	
> 		
> ___________________________________________________________
> New Yahoo! Mail is the ultimate force in competitive 
> emailing. Find out more at the Yahoo! Mail Championships. 
> Plus: play games and win prizes. 
> http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.