Cannot format MS Word 2003 File

Oxygen general issues.
craigj
Posts: 9
Joined: Thu Oct 29, 2009 1:51 pm

Cannot format MS Word 2003 File

Post by craigj »

I have:

- Opened Microsoft Word 2007
- Created a new document
- Inserted an image
- Saved the file as type: "Word 2003 XML document"

I now open the XML file in Oxygen. The XML file validates, however when I try to format the file, nothing happens i.e. the elements do not split onto new lines, indent, etc.

I regard myself as a fairly advanced Oxygen user and have never had any problems using the formatter before.

Here is a sample XML file created in Word: http://pastebin.com/DLxcLcwY
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Cannot format MS Word 2003 File

Post by adrian »

Hello,

The sample XML file has on the root element(w:wordDocument) the attribute: xml:space="preserve". This attribute prevents Oxygen's Format and Indent tool from actually formatting the document.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
craigj
Posts: 9
Joined: Thu Oct 29, 2009 1:51 pm

Re: Cannot format MS Word 2003 File

Post by craigj »

Adrian - great spot. Thanks for that.

In Word, I've found that you can't simply remove the xml:space="preserve" from the root element without messing up the document. The following transform will move the xml:space="preserve" from the <w:wordDocument> to each <w:t> - allowing you to indent the document without damaging the content.

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2">

<xsl:template match="@*|text()|comment()|processing-instruction()">
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="w:t">
<xsl:copy>
<xsl:attribute name="xml:space">preserve</xsl:attribute>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="w:wordDocument">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:if test="name()!='xml:space'">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Post Reply