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

Re: Grouping Problems XSLT2.0

Subject: Re: Grouping Problems XSLT2.0
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Wed, 14 Mar 2007 18:34:33 +0800
Re:  Grouping Problems XSLT2.0
Thanks David, it does the job. I was able to do the grouping for the subsections, but the the epigraph was the one that really bugged me. Then after seeing your post, i read the spec and saw that using group-adjacent requires an expression which makes the replace a nice work around for my problem (And for sure I would not think of this even after reading the spec, I always tend to use patterns and not think of expressions).

Again thanks a lot.
--
Jeff

David Carlisle wrote:
I don't know, there's something about the grouping attributes in
xsl-for-each-group I just don't seem to get, perhaps Michael could
comment?
Most of XSLT2 I just absorb and hardly ever refer to the spec, but I
_always_ have to check up the definition of for-each-group to check
which grouping attributes take a pattern, and which take an expression.
In the example below, the first, using group-adjacent, takes an
expression, but the second, using group-starting-with takes a pattern.
As is usally the case I got that wrong first time round. I must be
missing the "idea" behind this split, usually with XSL if you think
about things the right way, the xslt solution seesm perfectly natural,
it's just a matter of getting the brain to think the right way....


David




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

  <xsl:template match="section">
    <section>
      <xsl:for-each-group select="para" group-adjacent="replace(@class,'source','para')">
	<xsl:choose>
	  <xsl:when test="current-grouping-key() = 'epigraphpara'">
	    <epigraph>
	      <xsl:apply-templates select="current-group()"/>
	    </epigraph>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:for-each-group select="current-group()" group-starting-with="para[inline[ends-with(@class,'title')]]">
	    <subsection>
	      <title><xsl:apply-templates select="."/></title>
	      <xsl:apply-templates select="current-group()[position()!=1]"/>
	    </subsection>
	    </xsl:for-each-group>
	  </xsl:otherwise>	
	</xsl:choose>
      </xsl:for-each-group>
    </section>
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>


</xsl:stylesheet>





$ saxon8 epi.xml epi.xsl <?xml version="1.0" encoding="UTF-8"?> <section> <epigraph> <para class="epigraphpara">...</para> <para class="epigraphpara">...</para> <para class="epigraphpara">...</para> <para class="epigraphpara">...</para> <para class="epigraphsource">...</para> </epigraph> <subsection> <title> <para class="subsection1para"> <inline class="subsection1title">...</inline> </para> </title> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> </subsection> <subsection> <title> <para class="subsection1para"> <inline class="subsection1title">...</inline> </para> </title> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> <para class="subsection1para">...</para> </subsection> </section>

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.