Page 1 of 1
Cannot format MS Word 2003 File
Posted: Tue Feb 08, 2011 7:56 pm
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
Re: Cannot format MS Word 2003 File
Posted: Tue Feb 08, 2011 10:53 pm
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
Re: Cannot format MS Word 2003 File
Posted: Thu Feb 10, 2011 7:31 pm
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>