xsl-list
[Top] [All Lists]

RE: [xsl] Multiple for-each-group in a single template

2008-11-20 08:02:05
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[(_at_)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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--