[xsl] up-converting

Subject: [xsl] up-converting
From: Jim_Albright@xxxxxxxxxxxx
Date: Tue, 17 Aug 2004 13:02:52 -0400
My problem is to convert a WordML document to a standard XML document with 
hierarchy. There are 6 possible levels of div.
Sample input
<?xml version="1.0" encoding="UTF-8"?>
<document>
        <a>xxxxxxx</a>
        <b>level1 head</b>
        <c>level 2  head</c>
        <!-- no pattern in following content -->
        <d>blah</d>
        <e>blah</e>
        <f>blah</f>
        <c>level 2 head</c>
        <k>blah</k>
        <h>level 3 head</h>
        <i>blah</i>
        <j>blah</j>
        <c>level 2 head</c>
        <d>blah</d>
        <e>blah</e>
        <f>blah</f>
        <b>level 1 head</b>
        <c>level 2  head</c>
        <d>blah</d>
        <e>blah</e>
        <f>blah</f>
</document>

desired output
<?xml version="1.0" encoding="UTF-8"?>
<document>
        <Title>xxxxxxx</Title>
        <div>
                <head>level1 head</head>
                <div>
                        <head>level 2  head</head>
                        <!-- no pattern in following content -->
                        <d>blah</d>
                        <e>blah</e>
                        <f>blah</f>
                </div>
                <div>
                        <head>level 2  head</head>
                        <k>blah</k>
                        <div>
                                <head>level 3 head</head>
                                <i>blah</i>
                                <j>blah</j>
                        </div>
                </div>
                <div>
                        <head>level 2  head</head>
                        <d>blah</d>
                        <e>blah</e>
                        <f>blah</f>
                </div>
        </div>
        <div>
                <head>level1 head</head>
                <div>
                        <head>level 2  head</head>
                        <d>blah</d>
                        <e>blah</e>
                        <f>blah</f>
                </div>
        </div>
</document>


I can get the level 1 head in a div working properly but am stuck getting 
level 2 -6 to work at all.
I am using the group-starting-with of XSLT 2.0.

My WRONG XSLT is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="document">
                <document>
                        <xsl:apply-templates/>
                </document>
        </xsl:template>
        <xsl:template match="a">
                <title>
                        <xsl:value-of select="."/>
                </title>
                <xsl:for-each-group select="following::*" group-starting-with="b">
                        <div>
                                <head>
                                        <xsl:value-of select="self::b"/>
                                </head>
                                <xsl:for-each select="current-group()">
                                        <xsl:for-each-group select="following::*" group-starting-with="c">
                                                <div>
                                                        <head>
                                                                <xsl:value-of select="self::c"/>
                                                        </head>
                                                        <xsl:for-each select="current-group()">
                                                                <xsl:copy-of select="."/>
                                                        </xsl:for-each>
                                                </div>
                                        </xsl:for-each-group>
                                </xsl:for-each>
                        </div>
                </xsl:for-each-group>
        </xsl:template>
</xsl:stylesheet>



Jim Albright
704 843-0582
Wycliffe Bible Translators

Current Thread