How to: Generate autonumbered lists using WordML (2003)

I was reading today an internal distribution list and I saw an interesting thread about autonumbered lists using WordML (2003):

"I embarked on a journey to try and transform InfoPath rich text (xhtml) to WordML. I encounter a problem when I try to transform a rich text node that contains multiple numbered lists: in the rich text they both number from 1-3, but in Word the result is 1,2,3 and 4,5,6."

Zander Westendarp provides a great workaround: If you increment the value of the w:listDefId elements for each element, you can get autonumbered lists that always restart the numbering.

When I work with WordML or SpreadsheetML, I always build a template of the document/spreadsheet that I want to generate and save it as XML. It's the best way to get started with the code that you want to generate. I made an experiment to test this approach and explore the resulting WordML. Follow these simple steps...

  1. Start Microsoft Word 2003.

  2. Create a document with two sets of numbered lists as shown in Figure 1:


    Figure 1. Create two sets of autonumbered lists

  3. On the File menu, click Save As.

  4. In the Save as type list, select the XML Document (*.xml) option.

  5. In the File name box, type a new name for the document.

  6. Click Save.

Once you create the XML Document file, you can open the file using a text editor program to explore the content of the file. Find all the w:listDef elements and you will see how the w:listDefId attribute is always incremented.

Tip: If you want to see a nice and readable indented XML file, see this blog entry.

I know that WordML is a big topic and every document is a separate story. Newsgroups, forums, and DLs are always full of different questions. Taking about lists is just a single topic - that by the way is huge and complex by itself. Fortunately there are documents, articles, books, and cool bloggers who share their knowledge.

Here are some WordML resources that I use when I am stuck with WordML:

  1. Overview of WordprocessingML.
  2. XML Schema Reference
  3. Office 2003 XML
  4. Office 2003 XML for Power Users
  5. Powering Office 2003 with Office XML
  6. XML in Office 2003: Information Sharing with Desktop XML 

If you want to learn more about lists and WordML, read Oleg Tkachenko's blog entry: Generating WordprocessingML using XSLT: Lists. Also read John Durant's blog entry: WordProcessingML, XML, and Lists.

Finally, to learn WordML, divide and conquer, that's my strategy...