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

Re: position behavior in nested grouping

Subject: Re: position behavior in nested grouping
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 30 Jul 2009 15:42:18 +0200
Re:  position behavior in nested grouping
Ganesh Babu N wrote:
all those should be clubbed into single section by taking group-adjcent.

The output should be

                       <sections>
                              <section-title>Contents</section-title>
                          <section>
                               <section-head>Abstracts of the Series
of Fascia Congress - Part
4</section-head>
                               <para>
                                       <page>270</page>
                               </para>
                          </section>
                         <section>
                            <section-head/>
                              <para>
                                       <page>271</page>
                               </para>
                               <para>
                                       <page>271</page>
                               </para>
                          </section>
                          <section>
                               <section-head>Abstracts of the Series
of Fascia Congress - Part
4</section-head>
                               <para>
                                       <page>272</page>
                               </para>
                       </section>
                       <section>
                               <section-head>Prevention &amp;
Rehabilitation</section-head>
                               <section-subhead>Editorial</section-subhead>
                               <para>
                                       <page>273</page>
                               </para>
                               <para>
                                       <page>277</page>
                               </para>
                       </section>
                       <section>
                               <section-subhead>Learning
Methodology</section-subhead>
                               <para>
                                       <page>284</page>
                               </para>
                       </section>
               </sections>

If you know that you want group-adjacent then it is only a slight change from the earlier stylesheet:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="articles">
<sections>
<section-title>Contents</section-title>
<xsl:for-each-group select="row" group-adjacent="if (col[2] = '') then '' else tokenize(col[2], '\|')[1]">
<xsl:choose>
<xsl:when test="contains(col[2], '|')">
<xsl:variable name="outer-key" select="current-grouping-key()"/>
<xsl:for-each-group select="current-group()" group-by="tokenize(col[2], '\|')[2]">
<section>
<xsl:if test="position() eq 1">
<section-head><xsl:value-of select="$outer-key"/></section-head>
</xsl:if>
<section-subhead><xsl:value-of select="current-grouping-key()"/></section-subhead>
<xsl:apply-templates select="current-group()"/>
</section>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<section>
<section-head><xsl:value-of select="current-grouping-key()"/></section-head>
<xsl:apply-templates select="current-group()"/>
</section>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</sections>
</xsl:template>


  <xsl:template match="row">
    <para>
      <page><xsl:value-of select="col[3]"/></page>
    </para>
  </xsl:template>
</xsl:stylesheet>

The problem why the previous solution skips the row elements with an empty col[2] child element is that the tokenize function returns an empty sequence for the empty string and that does not result in a group. But group-adjacent="if (col[2] = '') then '' else tokenize(col[2], '\|')[1]" avoids that problem and simply form a group for those elements with an empty col[2].

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

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-2007 All Rights Reserved.