xsl-list
[Top] [All Lists]

Re: grouping/position problem

2005-04-23 16:20:32

Actually, I need to correct two things on my reply to Mike; first the template needs to put the year variable within the year-grouped for-each (it was outside the for-each). So:

   <xsl:template match="list" mode="sort_author-year">
     <xsl:for-each-group select="item" group-by="@author">
       <xsl:sort select="current-grouping-key()"/>
       <xsl:for-each-group select="current-group()" group-by="@year">
         <xsl:sort select="current-grouping-key()" />
         <xsl:for-each select="current-group()">
           <xsl:variable name="year">
              <xsl:value-of select="current-grouping-key()"/>
               <xsl:if test="last() > 1">
                 <xsl:number value="position()" format="a"/>
               </xsl:if>
           </xsl:variable>
           <xsl:variable name="author-position" select="position()"/>
<xsl:variable name="shorten-author" as="xs:boolean"select="$author-position > 1" />
           <xsl:apply-templates select=".">
             <xsl:with-param name="year" select="$year"/>
<xsl:with-param name="shorten-author"select="$shorten-author"/>
           </xsl:apply-templates>
         </xsl:for-each>
       </xsl:for-each-group>
     </xsl:for-each-group>
   </xsl:template>

Therefore this is wrong:

... here's the expected result:

<result>
   <item>
      <shorten-author>false</shorten-author>
      <year>2001a</year>
   </item>
   <item>
      <shorten-author>true</shorten-author>
      <year>2001a</year>
   </item>
   <item>
      <shorten-author>true</shorten-author>
      <year>2002b</year>
   </item>
</result>

It should be:

<result>
   <item>
      <shorten-author>false</shorten-author>
      <year>2001a</year>
   </item>
   <item>
      <shorten-author>true</shorten-author>
      <year>2001a</year>
   </item>
   <item>
      <shorten-author>true</shorten-author>
      <year>2002</year>
   </item>
</result>

Note the last year.

Bruce


--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>