Re: [xsl] Is there a way to sometimes bypass a nested for-each group?

Subject: Re: [xsl] Is there a way to sometimes bypass a nested for-each group?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 24 Jul 2008 09:41:07 +0100
     <xsl:element name="Heading">
            <xsl:attribute name="entry">
              <xsl:value-of select="Heading/@entry"/>
            <xsl:value-of select="current-grouping-key()"/>

I believ you could replace that with

<xsl:copy-of select=Heading"/>

   <xsl:for-each-group select="current-group()" group-by="SubHeading">

so all elements in the current group that don't have a heading should
be get key () which isn't grouped, but you want a group so instead of
grouping on the element (which may not be there) group on its string
value (which will be "" so unheaded items will be grouped with key "")

 You could test for that but if you replace

        <xsl:element name="SubHeading">
                  <xsl:value-of select="current-grouping-key()"/>


 <xsl:copy-of select="SubHeading"/>

There is no need to test, it will just do nothing if there is no


<xsl:stylesheet version="2.0" 
  <xsl:output method="html" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="List">
      <!-- There is always a Heading element -->

      <xsl:for-each-group select="Item" group-by="Heading">
        <xsl:sort select="current-grouping-key()"/>
	 <xsl:copy-of select="Heading"/>

          <!-- Here is my nesting problem: the SubHeading element may not 
always be present -->

                <xsl:for-each-group select="current-group()" 
                <xsl:sort select="current-grouping-key()"/>
                <xsl:copy-of  select="SubHeading"/>

            <!-- the following sequence constructor needs to be executed 
whether or not there is a <SubHeading> -->

              <xsl:for-each select="current-group()">
              <xsl:sort select="Title"/>
              <xsl:sort select="Year"/>
              <xsl:sort select="IssueNumber"/>
              <xsl:sort select="Page"/>

<!-- Pass these through -->
  <xsl:template match="Title"><xsl:copy-of select="."/></xsl:template>
  <xsl:template match="Year"><xsl:copy-of select="."/></xsl:template>
   <xsl:template match="IssueName"><xsl:copy-of select="."/></xsl:template>
  <xsl:template match="Person"><xsl:copy-of select="."/></xsl:template>
  <xsl:template match="Page"><xsl:copy-of select="."/></xsl:template>

<!-- Discard or reformat these -->
  <xsl:template match="Heading "/>
  <xsl:template match="SubHeading" />
  <xsl:template match="IssueNumber"/>


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread