[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is there a way to sometimes bypass a nested for-ea

Subject: Re: 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
Re:  Is there a way to sometimes bypass a nested for-ea
     <xsl:element name="Heading">
            <xsl:attribute name="entry">
              <xsl:value-of select="Heading/@entry"/>
            </xsl:attribute>
            <xsl:value-of select="current-grouping-key()"/>
          </xsl:element>

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:element>

by

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

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



David


<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>
  <xsl:strip-space elements="*"/>

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

      <xsl:for-each-group select="Item" group-by="Heading">
        <xsl:sort select="current-grouping-key()"/>
        <Item>
	 <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()" 
group-by="string(SubHeading)">
                <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"/>
              <Article>
                <xsl:apply-templates/>
              </Article>
            </xsl:for-each>
             </xsl:for-each-group>
        </Item>
       </xsl:for-each-group>
    </List>
  </xsl:template>

<!-- 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"/>

</xsl:stylesheet>

________________________________________________________________________
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.