Re: [xsl] XSL-FO group by problem

Subject: Re: [xsl] XSL-FO group by problem
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 27 Oct 2009 14:09:44 -0400
At 2009-10-27 11:00 -0700, Mark Wilson wrote:
In an XSLT-FO style sheet, I have created groups similar to the one shown at the end of this email.

Fine.


I have one template for formatting the <CatalogNumber> and another for formatting the remaining data. The <CatalogNumber> is always identical in a group, but the remaining information differs. I want a single copy of the <CatalogNumber> and one copy each of all of the remaining information from each <Item>as indicated in the output below (I can format everything, that's not my problem, I just can't get the single copy of the <CatalogNumber>).

What you are missing is that your current node at the beginning of <xsl:for-each-group> is at the first member of the group selected.


Output:
4: New issues: Czech Republic, May/Jun 1993, p. 22; Letters to the editor, Mar/Apr 2002, p. 27; Joint issues, Nov/Dec 2002, p.18.


My style sheet code is:
<xsl:for-each-group select="Item" group-by="concat(Prefix, CatalogNumber, Range)">

At this point, <xsl:value-of select="CatalogNumber"/> will give you "4" because your current node is the first <Item> of the group of <Item> elements.


In the classroom I tell students to read the instruction as if it were written:

<xsl:for-the-first-member-of-each-group .....

... and then to work with the other members of the group using current-group().

           <fo:block xsl:use-attribute-sets="base">
               <xsl:for-each select="current-group()">

<!--    What do I put here so that I only get one copy of the Catalog Number?
         (This code seems to go into an endless loop.)
-->

You put the processing of the catalogue number before the <xsl:for-each>, not inside.


<xsl:apply-templates select="CatalogNumber" mode="do"/>

Move that line up before the <xsl:for-each/>


<xsl:apply-templates select="Title" mode="do"/>

               </xsl:for-each>
           </fo:block>
       </xsl:for-each-group>

I hope this helps.


. . . . . . . . . . . . . . Ken


-- Upcoming: hands-on XSLT, XQuery and XSL-FO Washington DC Nov 2009 Interested in other classes? http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread