|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Convert Word XML to Hierarchical XML using XSLT
Hi,
Tempore 11:40:05, die 09/16/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Rod Coate <Rod.Coate@xxxxxxxxxxxxxxxxx>: 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? The ouput XML does not seem to have a recursive structure. You'll have to specify the instructions in a non-generic way: <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> </xsl:stylesheet> regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Gaudiam omnibus traderat W3C, nec vana fides
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








