Re: [xsl] Converting WordML to a XHTML list

Subject: Re: [xsl] Converting WordML to a XHTML list
From: "cking" <cking@xxxxxxxxxx>
Date: Thu, 26 Aug 2004 00:03:01 +0200
Hi Lincoln,

Here's a possible solution, using recursion: 

<xsl:template match="w:p">
    <xsl:choose>
        <xsl:when test="w:pPr/w:listPr">
            <xsl:if test="not(preceding-sibling::w:p[1]/w:pPr/w:listPr)">
                <xsl:apply-templates select="w:r/w:t" mode="list-begin"/>
            </xsl:if>
        </xsl:when>
        <xsl:when test="w:pPr/w:pStyle/@w:val='Heading5'">
            <h2><xsl:value-of select="w:r/w:t"/></h2>
        </xsl:when>
        ....
        <xsl:otherwise>
            <p><xsl:value-of select="w:r/w:t"/></p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="w:t" mode="list-begin">
    <ol>
        <xsl:apply-templates select="." mode="list-item-recursive"/>
    </ol>
</xsl:template>

<xsl:template match="w:t" mode="list-item-recursive">
    <li><xsl:value-of select="."/></li>
    <xsl:variable name="next" select="../../following-sibling::w:p[1]"/>
    <xsl:if test="$next/w:pPr/w:listPr">
        <xsl:apply-templates select="$next/w:r/w:t" mode="list-item-recursive"/>
    </xsl:if>
</xsl:template>

I hope this can clear up the mud? :)
Anton Triest

Wednesday, August 25, 2004 3:41 PM, Lincoln Mitchell wrote:
>
> I can see where you are going but a list of items maybe in other locations
> in the wordml so "//w:t[../../w:pPr/w:listPr]" will match them too.
> 
> However as list items will be in one block, maybe we create a rule like
> this:
> 1. For 1st "w:p/w:pPr/w:listPr" create "<OL>" and "<li>...</li>"
> 2. While "following-sibling" = "w:p/w:pPr/w:listPr" do "<li>...</li>"
> 3. </OL>
> 
> Clear as mud?
> 
> 
> If no resolve this time round I will send complete xsl and xml.
> 
> Linc

Current Thread