|
Subject: RE: [xsl] XSLT2: Keys vs. xsl:choose to distinguish groups From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 15 Mar 2007 12:51:18 -0000 |
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: [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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XSLT2: Keys vs. xsl:choos, David Carlisle | Thread | Re: [xsl] XSLT2: Keys vs. xsl:choos, Yves Forkl |
| Re: SV: Re: [xsl] fo spaces, Abel Braaksma | Date | RE: [xsl] limit a string to a certa, Gannon Dick |
| Month |