xsl-list
[Top] [All Lists]

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

2007-03-15 05:51:36
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(_dot_)Forkl(_at_)srz(_dot_)de] 
Sent: 15 March 2007 12:31
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--