|
Subject: [xsl] Multiple for-each-group in a single template From: "V.Ramkumar" <v.ramkumar@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 20 Nov 2008 16:20:11 +0530 |
Hi List,
I am getting duplicate when use multiple for-each-group in a single template
(based on single parent). Please find mistakes in my xslt.
Input:
<body>
<p class="heading-1">Heading 1</h1>
<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</h2>
<p>para 1</p>
<p class="exercise">para 2</p>
<p class="exercise">para 3</p>
<p>para 4</p>
</body>
Exp.Output:
<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>
My XSLT: (sample)
<xsl:template match="body">
<body>
<xsl:if test="p[@class='box']">
<xsl:for-each-group select="*"
group-adjacent="string(self::p/@class[contains(.,'box')])">
<xsl:choose>
<xsl:when
test="self::p/@class[contains(.,'box')]">
<box type="box"
page="{replace(preceding-sibling::p[@class='pageNumber'][1],'Page ','')}">
<xsl:apply-templates
select="current-group()"/>
</box>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:if>
<xsl:if test="p[@class='exercise']">
<xsl:for-each-group select="*"
group-adjacent="string(self::p/@class[contains(.,'exercise')])">
<xsl:choose>
<xsl:when
test="self::p/@class[contains(.,'exercise')]">
<exercise>
<xsl:apply-templates
select="current-group()"/>
</exercise>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:if>
</body>
Regards,
Ramkumar
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] <xsl:call-template> XSLT , Pankaj Chaturvedi | Thread | RE: [xsl] Multiple for-each-group i, V.Ramkumar |
| RE: [xsl] <xsl:call-template> XSLT , Pankaj Chaturvedi | Date | RE: [xsl] Multiple for-each-group i, V.Ramkumar |
| Month |