RE: [xsl] current-group()[1] within xsl:for-each-group

Subject: RE: [xsl] current-group()[1] within xsl:for-each-group
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 2 Mar 2005 15:25:46 -0000
> I've got this in a template:
> 
>       <xsl:for-each-group select="mb3e:document" 
> group-by="mb3e:fam_id">
>         <xsl:sort select="mb3e:prim_sort_key"/>
>         <xsl:variable name="first-structured-number"
>                       
> select="esd:structured-number(current-group()[1])"/>
>         <xsl:apply-templates mode="mil" select="current-group()">
>           <xsl:with-param name="family-structured-number"
>                           select="$first-structured-number"/>
>           <xsl:sort select="mb3e:date_list/mb3e:date[@type='PUBL']"
>                     order="descending"/>
>         </xsl:apply-templates>
>       </xsl:for-each-group>
> 
> The esd:structured-number function is slow, so I only want to call it
> once per group.  Actually, the template that is applied within the
> xsl:for-each-group instruction has to call it for each mb3e:document
> element, but I want to avoid calling it more than once for 
> any of those
> elements (including the first, i.e. most recent):

I'm not sure what you mean by "the most recent document". current-group()[1]
selects the first item in the group currently being processed. You haven't
really shown enough of your source data for me to understand what you are
doing.
> 
>   <xsl:variable name="structured-number"
>                 select="if (position() = 1)
>                         then $family-structured-number
>                         else esd:structured-number(.)"/>

Where is this variable declared, and where is it used? The reference to
position() makes it highly context-sensitive. 
> 
> I think this works most of the time, but sometimes the
> family-structured-number parameter value (i.e. 
> $first-structured-number)
> is not the value that would be returned if the esd:structured-number
> function were called on the most recent mb3e:document element in the
> group.  For example, in once case it was the 7th most recent 
> of a group of 58.

As I say, I don't understand what you mean by "most recent", and I don't see
anything in your code that relates to the concept. You seem to be basing the
calculation on the first item in the current group.

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

Current Thread