• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

10. Word 2003 XML Hacks > 97. Remove Direct Formatting with XSLT

Remove Direct Formatting with XSLT

Strip out non-style-based formatting from Word documents.

A common “cleanup” task in Word is to remove any formatting from a document that hasn’t been applied with a style. It’s a bit of a chore within Word, but it turns out to be remarkably concise in XSLT.

The Code

Enter the following code in a standard text editor such as Notepad and save it as removeDirectFormatting.xsl:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

  <!-- By default, recursively copy everything through -->
  <xsl:template match="@*|node( )">
    <xsl:copy>
      <xsl:apply-templates select="@*|node( )"/>
    </xsl:copy>
  </xsl:template>

  <!-- Remove all direct paragraph formatting -->
  <xsl:template match="w:p/w:pPr/*[not(self::w:pStyle)]"/>

  <!-- Remove all direct run formatting -->
  <xsl:template match="w:r/w:rPr/*[not(self::w:rStyle)]"/>

</xsl:stylesheet>

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint