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

RE: Multiple for-each-group in a single template

Subject: RE: Multiple for-each-group in a single template
From: "V.Ramkumar" <v.ramkumar@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Nov 2008 18:33:01 +0530
RE:  Multiple for-each-group in a single template
Dear David.

Thanks. It's working fine. I understand the logic.

But Section closed before any section it should close before the same-level.

Xsl:

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

<xsl:output method="xml" indent="yes" 
	    omit-xml-declaration="yes" />

<xsl:strip-space elements="*"/>

<xsl:template match="html">
 <chapter>
  <xsl:apply-templates/>
 </chapter>
</xsl:template>

<xsl:template match="*">
 <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
 </xsl:copy>
</xsl:template>
	<xsl:template match="body">
	<body>
		<xsl:for-each-group select="*"
group-starting-with="p[contains(@class,'heading-')]">
			<xsl:choose>
				<xsl:when
test="self::p/@class[contains(.,'heading-1')]">
					<section1>
						<xsl:call-template name="g">
							<xsl:with-param
name="e" select="current-group()"/>
						</xsl:call-template>
					</section1>
				</xsl:when>
				<xsl:when
test="self::p/@class[contains(.,'heading-2')]">
					<section2>
						<xsl:call-template name="g">
							<xsl:with-param
name="e" select="current-group()"/>
						</xsl:call-template>
					</section2>
				</xsl:when>
				<xsl:when
test="self::p/@class[contains(.,'heading-3')]">
					<section3>
						<xsl:call-template name="g">
							<xsl:with-param
name="e" select="current-group()"/>
						</xsl:call-template>
					</section3>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="g">
						<xsl:with-param name="e"
select="current-group()"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each-group>
	</body>
	</xsl:template>

	<xsl:template name="g">
		<xsl:param name="e"/>
		<xsl:for-each-group select="$e"
group-adjacent="string(self::p/@class)">
			<xsl:choose>
				<xsl:when
test="self::p/@class[contains(.,'box')]">
					<box type="box"
page="{preceding-sibling::p[@class='pageNumber'][1]}">
						<xsl:apply-templates
select="current-group()"/>
					</box>
				</xsl:when>
				<xsl:when
test="self::p/@class[contains(.,'exercise')]">
					<exercise>
						<xsl:apply-templates
select="current-group()"/>
					</exercise>
				</xsl:when>
				<xsl:when
test="self::p/@class[contains(.,'marginText')]">
					<margintext type="quotation">
						<xsl:apply-templates
select="current-group()"/>
					</margintext>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates
select="current-group()"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each-group>
	</xsl:template>

Regards,
Ramkumar

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.