Skip to Content
Office 2003 XML
book

Office 2003 XML

by Simon St. Laurent, Mary McRae, Evan Lenz
May 2004
Beginner to intermediate
592 pages
16h 29m
English
O'Reilly Media, Inc.
Content preview from Office 2003 XML

Creating Word Documents

It’s very easy to create Word documents from XSLT. We saw the definitive “Hello, World” example for WordprocessingML in Chapter 2. Example 3-1 shows the “Hello, World” example for creating a Word document from XSLT.

Example 3-1. Creating a Word document from XSLT

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
   
  <xsl:template match="/">
    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument>
      <xsl:attribute name="xml:space">preserve</xsl:attribute>
      <w:body>
        <w:p>
          <w:r>
            <w:t>Hello, World!</w:t>
          </w:r>
        </w:p>
      </w:body>
    </w:wordDocument>
  </xsl:template>
   
</xsl:stylesheet>

As you can see, there’s little to it, beyond slapping xsl:stylesheet and xsl:template elements around the w:wordDocument element. The only additional provisions you need to make are for generating the mso-application PI and the xml:space="preserve" directive in the result. (Using the xsl:attribute element as opposed to a literal xml:space attribute ensures that whitespace will be preserved in the result but not in the stylesheet.)

Obviously, Example 3-1 isn’t terribly interesting in its own right. What is interesting is how you can extend it. With XSLT’s power and a basic knowledge of WordprocessingML at your disposal, you can create dynamic Word documents quite easily. We’ll take a look at one example of doing this: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

XML in Office 2003: Information Sharing with Desktop XML

XML in Office 2003: Information Sharing with Desktop XML

Charles F. Goldfarb, Priscilla Walmsley
Microsoft® Excel® 2010 Formulas & Functions Inside Out

Microsoft® Excel® 2010 Formulas & Functions Inside Out

Helmut Reinke Egbert Jeschke Sara Unverhau, Eckehard Pfeifer, Bodo Fienitz, and Jens Bock
Professional XML

Professional XML

Thiru Thangarathinam, Bill Evjen, Alessandro Vernet, Sam Ferguson, Kent Sharkey, Michael Kay

Publisher Resources

ISBN: 0596005385Purchase bookErrata Page