Subject: Re: [xsl] XSLT 1.0: Grouping Adjacent Elements in Embedded Lists From: Geert Josten <Geert.Josten@xxxxxxxxxxx> Date: Sat, 06 Nov 2004 11:22:47 +0100 |
<xsl:template match="OL_LI"> <!-- suppress at this level, you are outside the top-level wrappers! --> </xsl:template>
<xsl:template match="EM_OL_LI"> <!-- suppress at this level, you are outside the top-level wrappers! --> <!-- or isn't it? --> <xsl:if test="not(preceding-sibling::*[1][self::OL_LI or self::EM_OL_LI])"> <xsl:message terminate="yes">Dangling EM_OL_LI, should not occur!</xsl:message> </xsl:if> </xsl:template>
<xsl:template match="EM_OL_LI" mode="continue-top-level-list"> <!-- suppress at this level, you are outside the sub-level wrappers! --> <!-- but still continue as a next OL_LI might occur after the EM_OL_LI chain --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-top-level-list"/> </xsl:template>
<xsl:template match="EM_OL_LI[preceding-sibling::*[1][self::OL_LI]]" mode="continue-top-level-list"> <!-- jump to sub-level-list group to start sub level nesting --> <xsl:apply-templates select="." mode="start-sub-level-list"/> <!-- but still continue as a next OL_LI might occur after the EM_OL_LI chain --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-top-level-list"/> </xsl:template>
Cheers, Geert
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--+ ============================================================== | output +-->
<!--+ ============================================================== | main group +-->
<xsl:template match="DATA"> <html> <xsl:apply-templates select="node()" /> </html> </xsl:template>
<xsl:template match="OL_LI"> <!-- suppress at this level, you are outside the top-level wrappers! --> </xsl:template>
<xsl:template match="EM_OL_LI"> <!-- suppress at this level, you are outside the top-level wrappers! --> </xsl:template>
<!--+ ============================================================== | group start-top-level-list +-->
<xsl:template match="@*|node()" mode="start-top-level-list"> <!-- jump back to main group, if nothing else matches! --> <xsl:apply-templates select="." /> </xsl:template>
<xsl:template match="OL_LI" mode="start-top-level-list"> <p> <ol> <li><xsl:apply-templates /></li> <!-- jump to continue-top-level-list to find out whether sub level list should be started --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-top-level-list"/> </ol> </p> </xsl:template>
<xsl:template match="EM_OL_LI" mode="start-top-level-list"> <!-- suppress at this level, you are outside the top-level wrappers! --> </xsl:template>
<!--+ ============================================================== | group continue-top-level-list +-->
<xsl:template match="*" mode="continue-top-level-list"> <!-- end continuation as an element is encountered that doesn't belong in this group --> </xsl:template>
<xsl:template match="EM_OL_LI" mode="continue-top-level-list"> <!-- suppress at this level, you are outside the sub-level wrappers! --> <!-- but still continue as a next OL_LI might occur after the EM_OL_LI chain --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-top-level-list"/> </xsl:template>
<xsl:template match="EM_OL_LI[preceding-sibling::*[1][self::OL_LI]]" mode="continue-top-level-list"> <!-- jump to sub-level-list group to start sub level nesting --> <xsl:apply-templates select="." mode="start-sub-level-list"/> <!-- but still continue as a next OL_LI might occur after the EM_OL_LI chain --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-top-level-list"/> </xsl:template>
<!--+ ============================================================== | group start-sub-level-list +-->
<xsl:template match="@*|node()" mode="start-sub-level-list"> <!-- jump back to continue-top-level-list, if nothing else matches! --> <xsl:apply-templates select="." mode="continue-top-level-list" /> </xsl:template>
<xsl:template match="EM_OL_LI" mode="start-sub-level-list"> <p> <ol> <li><xsl:apply-templates /></li> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-sub-level-list"/> </ol> </p> </xsl:template>
<!--+ ============================================================== | group continue-sub-level-list +-->
<xsl:template match="*" mode="continue-sub-level-list"> <!-- end continuation as an element is encountered that doesn't belong in this group --> </xsl:template>
<xsl:template match="EM_OL_LI" mode="continue-sub-level-list"> <!-- output sub level list item --> <li><xsl:apply-templates /></li> <!-- continue with following EM_OM_LI elements --> <xsl:apply-templates select="following-sibling::node()[1]" mode="continue-sub-level-list"/> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT 1.0: Grouping Adjace, Joe Heidenreich | Thread | RE: [xsl] XSLT 1.0: Grouping Adjace, Joe Heidenreich |
[xsl] Help needed to make XSL for m, Lim Siew Yin | Date | Re: [xsl] Help needed to make XSL f, Geert Josten |
Month |