Webucator uses an XHTML-based courseware system. At publishing time, we compile all the lessons, written in XHTML, into a single large XML file and then we use XSLT/XSL-FO to create a PDF.
We are now planning to submit several of our courses to the Microsoft Courseware Library. To do so, we need to get them into Microsoft Word. It would be a ton of work to convert them manually and then we would have to keep both version in sync.
So, I dove into WordProcessingML. I’ve looked at it several times before, but always walked away after an hour or two of frustration. This time, I pushed further as we now have a real incentive to get it working. It’s actually kind of cool. Maybe I’ll write a WordProcessingML course someday? Interested?
Anyway, right now I’m struggling with an XSLT problem that I hope someone might be able to help me with.
I’m starting with the following code from my source XML:
1 2 3 4 5 | <p> Some text and inline elements. <img/> Some more text and inline elements </p> |
And here’s my desired output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <w:p> <w:r> <w:t>Some text and inline elements.</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:jc w:val="center"/> </w:pPr> <w:r> <w:drawing> ... </w:drawing> </wr> </w:p> <w:p> <w:r> <w:t>Some more text and inline elements.</w:t> </w:r> </w:p> |
The issue is that the image needs to appear centered on a block by itself. I know there’s WordProcessingML markup for doing that within a paragraph, but I haven’t been able to get that to behave correctly even while working in Word 2010 directly.
In XSL-FO, this isn’t a problem, because you can simply nest one fo:block in another fo:block, but in WordProcessingML, that’s not allowed.
The above “Desired Output” markup works correctly in Word (meaning it displays like I want it to), but it’s an XSLT challenge.
Essentially, what I need is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <xsl:template match="img"> </w:p> <w:p> <w:pPr> <w:jc w:val="center"/> </w:pPr> <w:r> <w:drawing> ... </w:drawing> </w:r> </w:p> <w:p> </xsl:template> |
But, of course, that’s not well-formed XML, so it chokes.
Anybody know of a solution for this sort of problem?




