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

RE: XSLT2: Keys vs. xsl:choose to distinguish groups

Subject: RE: XSLT2: Keys vs. xsl:choose to distinguish groups
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 15 Mar 2007 12:51:18 -0000
RE:  XSLT2: Keys vs. xsl:choose to distinguish groups
Why not use apply-templates to despatch based on the first member of the
group:

<xsl:for-each-group....
  <xsl:apply-templates select="current-group()[1]" mode="process-group"/>

<xsl:template match="A" mode="process-group">
  <xsl:for-each select="current-group()">
    ...

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

> -----Original Message-----
> From: Yves Forkl [mailto:Y.Forkl@xxxxxx] 
> Sent: 15 March 2007 12:31
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XSLT2: Keys vs. xsl:choose to distinguish groups
> 
> Hi list members,
> 
> several weeks ago, your much appreciated help enabled me to 
> tackle my grouping problem. Now I am thinking about some 
> refactoring, so I'll briefly resume it before asking you 
> again for help. It's basically a classic heading-type 
> grouping problem, but with some additional difficulties. From 
> a flat structure like
> 
> <A/>
> <x/>
> <B/>
> <x/>
> <y/>
> <C/>
> <x/>
> 
> I am building this hierarchical structure:
> 
> <part_A>
>    <item_specific_to_A/>
>    <A/>
>    <x/>
> </part_A>
> <part_B>
>    <B/>
>    <x/>
>    <item_specific_to_B/>
>    <y/>
> </part_B>
> <part_C>
>    <C/>
>    <item_specific_to_C/>
>    <x/>
> </part_C>
> 
> This is to say, each group needs specific processing. 
> Currently I am using xsl:choose to recognize a group by its "leader":
> 
> <xsl:for-each-group select="*" group-starting-with="A|B|C">
>    <xsl:choose>
> 
>      <xsl:when test="current-group()[1] = A">
>        <part_A>
>          <item_specific_to_A/>
>          <xsl:apply-templates select="current-group()"/>
>        </part_A>
>      </xsl:when>
> 
>      <!-- xsl:when statements for the other two cases left out -->
> 
>    </xsl:choose>
> </xsl:for-each-group>
> 
> <!-- template rules for copying the individual elements left out -->
> 
> 
> My question is: Is it feasible (and reasonable) to avoid 
> using xsl:choose here but instead select a group's treatment 
> based on a key (because some groups might need the same kind 
> of processing)? I think of having just a single call to the 
> key function which would then dispatch the call to one out of 
> a list of user-defined functions or named templates, which 
> would finally return the resulting sequence.
> 
> Am I dreaming here of a control flow "too dynamic" to be 
> legal in XSLT2? 
> If not, what could the key definition and function call look like?
> 
>    Yves

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.