Outlook, .NET, and WordML- the SIXTH of a short series

Well, I come to the end of this little series. In this entry, I will show you some of the XSL I wrote to format my Word document from the XML file. It's not too hard to follow, but I will focus only on the most interesting parts. I have trimmed out some things so that it is shorter by taking out some of the content and putting in a comment.

This stylesheet goes through the source XML and looks only for tasks where the Note element contains the word "Kunicki".

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
    <xsl:template match="/">
        <xsl:processing-instruction name="mso-application">progid="Word.Document"</xsl:processing-instruction>
    <xsl:template match="tns:Tasks">
  <xsl:comment>Word style stuff goes here</xsl:comment>
  <xsl:comment>I trimmed out the document-wide behaviors here</xsl:comment>
     <xsl:apply-templates select="tns:SummaryInfo"/>
             <xsl:apply-templates select="tns:Task[contains(tns:Notes,'Kunicki')]"/>     
    <xsl:template match="tns:SummaryInfo">
  <xsl:comment>I trimmed out some WordML output here</xsl:comment>
    <xsl:template match="tns:Task">
   <w:pStyle w:val="Heading3"/>
    <w:b w:val="off"/>
                    <xsl:value-of select="@Subject"/>
    <w:b w:val="off"/>
    <w:color w:val="3366FF"/>
   <w:t> (Percent Complete= <xsl:value-of select="@PercentComplete"/>)</w:t>
        <xsl:apply-templates select="tns:Notes"/>       
    <xsl:template match="tns:Notes">
  <xsl:comment>Table WordML output goes here</xsl:comment>

the main thing to keep in mind is that Word 2003 is (fortunately) not terribly forgiving about ill-formed XML. If you have errors in your output, Word won't be happy. If you are wondering how to get going with WordML, check out the Office Developer Center (http://msdn.microsoft.com/office) and check out the section on XML. Also, Oleg's blog is really, really good (http://www.tkachenko.com/blog/).

Rock thought for the day: In lists of the best guitarists of all-time, Billy Corgan is regularly overlooked. He is amazing. If you are unconvinced, check out "Why Am I So Tired" on the EarPhoria album. It is a 15 minute solo essentially, not all fireworks, just great guitar layering.

Rock on!

Skip to main content