|
[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
Dear David,
As you told, Input and required out are given below,
Input:
<html>
<body>
<p class="heading-1">Heading 1</p>
<p>para 1</p>
<p class="box">para 2</p>
<p class="box">para 3</p>
<p>para 4</p>
<p class="heading-2">Heading 2</p>
<p>para 1</p>
<p class="exercise">para 2</p>
<p class="exercise">para 3</p>
<p>para 4</p>
</body>
</html>
Exp.Output:
<chapter>
<body>
<section title="Heading-1">
<p>para 1</p>
<box>
<p>para 2</p>
<p>para 3</p>
</box>
<p>para 4</p>
</section>
<section title="Heading-2">
<p>para 1</p>
<excecise>
<p>para 2</p>
<p>para 3</p>
</excecise>
<p>para 4</p>
</section>
</body>
</chapter>
My XSLT:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" encoding="iso-8859-1"
omit-xml-declaration="yes" />
<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-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:for-each-group select="*"
group-starting-with="p[@class='heading-1']">
<xsl:choose>
<xsl:when
test="self::p/@class[contains(.,'heading-1')]">
<section1>
<xsl:apply-templates
select="current-group()"/>
</section1>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</body>
</xsl:template>
Regards,
Ramkumar.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








