Partilhar via


Microsoft Word 2003 – one XML InfoSet, many renditions

How to write your thoughts once and produce as many renditions as you want? Here is one way using Microsoft Word 2003 XML capabilities:

 

Start with the structure of your thoughts as a XML schema, let’s say:

 

<?xml version="1.0" encoding="utf-8" ?>

<xs:schema

  targetNamespace="https://marcod.org/Doc1"

  elementFormDefault="qualified"

  xmlns="https://marcod.org/Doc1"

  xmlns:mstns="https://marcod.org/Doc1"

  xmlns:xs="https://www.w3.org/2001/XMLSchema">

 

<xs:element name="Doc1">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" />

      <xs:element name="section" minOccurs="0" maxOccurs="unbounded">

        <xs:complexType>

          <xs:sequence>

            <xs:element name="subtitle" type="xs:string" minOccurs="0" maxOccurs="unbounded" />

            <xs:element name="p" type="xs:string" minOccurs="0" maxOccurs="unbounded" />

          </xs:sequence>

        </xs:complexType>

      </xs:element>

    </xs:sequence>

  </xs:complexType>

</xs:element>

</xs:schema>

 

An XML instance for such a structure is for example:

 

<Doc1 xmlns="https://marcod.org/Doc1">

  <title>doc1 instance1</title>

  <section>

    <subtitle>sub1</subtitle>

    <p>text1</p>

  <p>text2</p>

  </section>

  <section>

    <subtitle>sub2</subtitle>

    <p>text1</p>

  </section>

  <section>

    <subtitle>sub3</subtitle>

    <p>text1</p>

    <p>text2</p>

    <p>text3</p>

  </section>

</Doc1>

 

A basic rendition could be produced by this XSLT stylesheet:

 

<?xml version="1.0" encoding="UTF-8" ?>

<x:stylesheet

  version="1.0" xmlns:x=https://www.w3.org/1999/XSL/Transform

  xmlns:t="https://marcod.org/Doc1">

 

<x:output method="html" />

 

<x:template match="/">

 

<html>

<title><x:value-of select="/t:Doc1/t:title" /></title>

<style>

 P {text-align:justify}

</style>

<body>

 

<h1><x:value-of select="/t:Doc1/t:title" /></h1>

<x:apply-templates select="/t:Doc1/t:section" />

</body>

</html>

 

</x:template>

 

<x:template match="t:section">

<hr/>

<h2><x:value-of select="t:subtitle" /></h2>

<x:apply-templates select="t:p" />

</x:template>

 

<x:template match="t:p">

<p><x:value-of select="." /></p>

</x:template>

 

</x:stylesheet>

 

Now, in Word 2003:

 

-Select File / New...

-In New Document Task Pane, select XML document

-Select Templates and Add-Ins...

-In the XML Schema tab, select Add Schema...

-Select the .xsd file for our schema above

-Type an alias for such a schema

-Now write down your ideas and tag them as appropriate with the “Choose an element to apply to your current selection:” section of the XML Structure Task Pane.

-Or select an element and write your intended content between the tags

 

Dump you mind as you wish

Save your abstractions often, they are on an .xml file and represent the XML InfoSet of your ideas (this file is the source).

 

Want a particular rendition?

 

-In the XML Structure Task Pane, select XML Options...

-Check Save data only

-Check Apply custom transform

-Browse to the .xslt file (like the one above)

-Select File / Save As... (Apply transform and Save data only checkboxes are set)

-Provide a filename for that particular rendition, as of this example it is an HTML file, so type the name between double quotes and with .html extension

 

That’s it!