xsl-list
[Top] [All Lists]

[xsl] Re: Sorting on two levels

2015-04-15 08:50:46
The suggestion offered yesterday works great as far as the sorting, but I need 
to do certain things to each item in a group as it's output, such as wrapping 
each ID in an <a> element.  What I tried is shown below, but it results in 
@href containing *all* the ids for the group.  How do I process each item in a 
group separately?  Do I need to at some point just do <xsl:apply-templates 
select=" current-group()"> and then rely on templates for primary, secondary, 
etc.?  I did try that but couldn't seem to get it to work -- either I got no 
output, or I got the entire group in a chunk.

<xsl:template name="create-index">
    <ul>
       <xsl:for-each-group select="//indexterm" group-by="primary">
          <xsl:sort select="current-grouping-key()"/>
          <li>
             <xsl:value-of select="current-grouping-key(), 
if(not(current-group()/secondary)) then current-group()/@id else ()" 
separator=", "/>
             <xsl:if test="current-group()/secondary">
                <ul>
                   <xsl:for-each-group select="current-group()" 
group-by="secondary">
                      <xsl:sort select="current-grouping-key()"/>
                      <li>
                            <xsl:value-of select="current-grouping-key()"/>
                            <a>
                               <xsl:attribute name="href">
                                    <xsl:value-of select="current-group()/@id"/>
                               </xsl:attribute>
                               <xsl:value-of select="current-group()/@id" 
separator=", "/>
                           </a>
                      </li>
                   </xsl:for-each-group>
                </ul>
             </xsl:if>
          </li>
       </xsl:for-each-group>
    </ul>
</xsl:template>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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