Clifford W. Racz
Usenet Archive
- Joined
- Feb 12, 2004
- Messages
- 10
- Reaction score
- 0
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the collection that I need.
To begin, I am using xsltproc that conmes with Cygwin as my processor. I have no particular affinity to this processor except that it is open source and standards compliant. I don't like M$, but if using a M$ processing program will fix this transformation, then I will use it. xsltproc can be gotten here (for Windows platform):
http://www.zlatkovic.com/libxml.en.html
ftp://ftp.zlatkovic.com/pub/libxml/
(This is a windows port of libxslt, that comes with GNOME).
The problem is this:
As those of you who have worked with this type of problem, the WordML structure is a flat structure where the focus is on visual formatting. So, instead of a nicely nested list structure like HTML has, WordML has a linear collection of w
elements that contain a child <w:listPr> element, containing the list information. A typical Word paragraph that represents a list item is shown here:
<w
>
<w
Pr>
<w:listPr>
<w:ilvl w:val="0"/>
<w:ilfo w:val="2"/>
<wx:t wx:val="·" wx:wTabBefore="360" wx:wTabAfter="240"/> <wx:font wx:val="Symbol"/> </w:listPr> </w
Pr> <w:r> <w:t>Bulleted item 1</w:t> </w:r> </w
>
The item <w:ilvl w:val="0"/> tells me that the level of nesting for this item is "0", i.e. the first level (zero based counting).
My model for processing this list was this: As I encounter the first <w
> that is a list item, represented by the xPath match="w
[descendant-or-self::w
Pr/w:listPr][1]", then I grab the entire collection of following-sibling elements that are paragraphs with listPr children. This is "grabbing the list". I call a template and pass this list to the template.
The template itself is a recursive template. Whenever I encounter a "transitional list item" (one that is at a level greater then the current level being processed by the template), I want to grab the sub-collection of list elements above my current level, enclose them in <ol></ol> and then call the template again with the new collection.
So... what is my problem? Let us pretend that my list looks like this:
* Bulleted item 1
* Bulleted item 2
o First level nesting, bulleted item 2-1
o First level nesting, bulleted item 2-2
* Bulleted item 3
* Bulleted item 4
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 5
* Bulleted item 6
When I am processing level 0, I don't have any issues until I grab the items on level 1. When I do, I not only get the items 2-1 and 2-2, but also 4-1, 4-2, 4-3, and 4-4. I have tried tweaking the xPath for this list, but to no avail. My output looks like this with my method:
* Bulleted item 1
* Bulleted item 2
o First level nesting, bulleted item 2-1
o First level nesting, bulleted item 2-2
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 3
* Bulleted item 4
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 5
* Bulleted item 6
This following 2 items are the stripped down WordML and stripped down XSLT for this transformation, to make this posting not insanely long. If anyone can contribute to this problem or has already solved it, I would be most grateful for feedback.
Cliff
XSLT for processing the WordML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY tab " ">
<!ENTITY sp " ">
<!ENTITY crlf "
To begin, I am using xsltproc that conmes with Cygwin as my processor. I have no particular affinity to this processor except that it is open source and standards compliant. I don't like M$, but if using a M$ processing program will fix this transformation, then I will use it. xsltproc can be gotten here (for Windows platform):
http://www.zlatkovic.com/libxml.en.html
ftp://ftp.zlatkovic.com/pub/libxml/
(This is a windows port of libxslt, that comes with GNOME).
The problem is this:
As those of you who have worked with this type of problem, the WordML structure is a flat structure where the focus is on visual formatting. So, instead of a nicely nested list structure like HTML has, WordML has a linear collection of w
<w
<w
<w:listPr>
<w:ilvl w:val="0"/>
<w:ilfo w:val="2"/>
<wx:t wx:val="·" wx:wTabBefore="360" wx:wTabAfter="240"/> <wx:font wx:val="Symbol"/> </w:listPr> </w
The item <w:ilvl w:val="0"/> tells me that the level of nesting for this item is "0", i.e. the first level (zero based counting).
My model for processing this list was this: As I encounter the first <w
The template itself is a recursive template. Whenever I encounter a "transitional list item" (one that is at a level greater then the current level being processed by the template), I want to grab the sub-collection of list elements above my current level, enclose them in <ol></ol> and then call the template again with the new collection.
So... what is my problem? Let us pretend that my list looks like this:
* Bulleted item 1
* Bulleted item 2
o First level nesting, bulleted item 2-1
o First level nesting, bulleted item 2-2
* Bulleted item 3
* Bulleted item 4
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 5
* Bulleted item 6
When I am processing level 0, I don't have any issues until I grab the items on level 1. When I do, I not only get the items 2-1 and 2-2, but also 4-1, 4-2, 4-3, and 4-4. I have tried tweaking the xPath for this list, but to no avail. My output looks like this with my method:
* Bulleted item 1
* Bulleted item 2
o First level nesting, bulleted item 2-1
o First level nesting, bulleted item 2-2
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 3
* Bulleted item 4
o First level nesting, bulleted item 4-1
o First level nesting, bulleted item 4-2
o First level nesting, bulleted item 4-3
o First level nesting, bulleted item 4-4
* Bulleted item 5
* Bulleted item 6
This following 2 items are the stripped down WordML and stripped down XSLT for this transformation, to make this posting not insanely long. If anyone can contribute to this problem or has already solved it, I would be most grateful for feedback.
Cliff
XSLT for processing the WordML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY tab " ">
<!ENTITY sp " ">
<!ENTITY crlf "