Subject: Re: [xsl] Convert Word XML to Hierarchical XML using XSLT From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Fri, 16 Sep 2005 12:21:09 +0200 |
I need a bit of Guidance as to how to approach this problem. If I was coding in VBA then I could just count and compare Heading levels, but how do I do this in XSL?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/>
<xsl:template match="Word-Document"> <root> <xsl:apply-templates select="Heading1"/> </root> </xsl:template>
<xsl:template match="Heading1"> <xsl:copy> <Title><xsl:apply-templates/></Title> <Data> <xsl:apply-templates select="following::*[1]" mode="recursive"> <xsl:with-param name="parents" select="local-name()"/> <xsl:with-param name="level" select="'Heading2'"/> </xsl:apply-templates> </Data> </xsl:copy> </xsl:template>
<xsl:template match="Heading2"> <xsl:param name="parents"/> <xsl:copy><xsl:apply-templates/></xsl:copy> <xsl:apply-templates select="following::*[1]" mode="recursive"> <xsl:with-param name="parents" select="concat($parents,'-',local-name())"/> <xsl:with-param name="level" select="'Heading3'"/> </xsl:apply-templates> </xsl:template>
<xsl:template match="Heading3"> <xsl:param name="parents"/> <xsl:element name="{.}"> <xsl:apply-templates select="following::*[1]" mode="recursive"> <xsl:with-param name="parents" select="concat($parents,'-',local-name())"/> <xsl:with-param name="level" select="'Normal'"/> </xsl:apply-templates> </xsl:element> </xsl:template>
<xsl:template match="*" mode="recursive"> <xsl:param name="level"/> <xsl:param name="parents"/> <xsl:if test="local-name()=$level"> <xsl:apply-templates select="."> <xsl:with-param name="parents" select="$parents"/> </xsl:apply-templates> </xsl:if> <xsl:if test="not(contains($parents,local-name()))"> <xsl:apply-templates select="following::*[1]" mode="recursive"> <xsl:with-param name="level" select="$level"/> <xsl:with-param name="parents" select="$parents"/> </xsl:apply-templates> </xsl:if> </xsl:template>
regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Gaudiam omnibus traderat W3C, nec vana fides
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Convert Word XML to Hierarchi, Rod Coate | Thread | RE: [xsl] Convert Word XML to Hiera, Michael Kay |
[xsl] PART 3 -THE REVERSE DIRECTIO, Graves, Jim \(CONTR\ | Date | Re: [xsl] PART 3 -THE REVERSE DIRE, David Carlisle |
Month |