[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

Subject: Re: Convert Word XML to Hierarchical XML using XSLT
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Fri, 16 Sep 2005 12:21:09 +0200
convert word to xsl
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.