共用方式為


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...

Comments

  • Anonymous
    February 12, 2006
    Thanks for this. You have created a <a href="http://www.wheelchairservice.info">helpful</a> thing. I worked it out and it proved to be helpful. Thanks again

  • Anonymous
    March 08, 2006
    you can also just change the <w:list> element and leaf the listdef the same for all lists:

    <w:list w:ilfo="1">
    <w:ilst w:val="0" />
    <w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="1"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="2"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="3"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="4"><w:startOverride w:val="1"/></w:lvlOverride>
    </w:list>
    <w:list w:ilfo="2">
    <w:ilst w:val="1" />
    </w:list>
    <w:list w:ilfo="3">
    <w:ilst w:val="0" />
    <w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="1"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="2"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="3"><w:startOverride w:val="1"/></w:lvlOverride>
    <w:lvlOverride w:ilvl="4"><w:startOverride w:val="1"/></w:lvlOverride>
    </w:list>

    But either way it is realy ugly :-(

  • Anonymous
    March 08, 2006
    forgot to mention that your solution won't work as the list is machted via

    <w:ilfo w:value = "{list number}" ...
    and gets there the
    <w:ilst w:val="{listdefinition number}" ...

    and then looks into the
    <w:listDef wlistDefId="{listdefinition number}"

    that part is unique if word creates the list, my solution if you create it on your own allows you to have only one definition and only chnage the differently requiered w:list elements

    hope this helps, you can read more here:
    http://rep.oio.dk/Microsoft.com/officeschemas/wordprocessingml_article.htm

  • Anonymous
    January 08, 2008
    To me it seems the entire auto-numbering gets evaded by doing manual numbering instead. Every list entry has a wx:val set which indicates their actual number.

  • Anonymous
    May 29, 2009
    PingBack from http://paidsurveyshub.info/story.php?title=erika-ehrli-how-to-generate-autonumbered-lists-using-wordml-2003