Reputation: 45
I tried to convert a single XML file into a DOCX file, and I did it by transforming my XML into an XHTML by using XSLT, then open the XHTML on MS Word and save it as DOCX.
But my task is to convert any XML Structure (DITA, TEI, DocBook, etc.) to DOCX directly... are there any other way to do it?
I just can't find any sources for this. It's always DOCX to XML and not the other way around.
Upvotes: 2
Views: 7822
Reputation: 111621
Yes, you can use XSLT to transform from any of those XML formats to OOXML. XSLT is ideal for XML to XML transformations.
That said, each of the input XML formats you mention are fairly complex, and OOXML is immensely complex. Also, DOCX is actually an assembly of many components, including a document.xml
file in OOXML, packaged via Open Packaging Conventions.
To get started, I recommend that you target creation of a simple document that you first make manually in MS Word. Rename the file from a .docx
extension to a .zip
extension, and unzip the components and recover the word/document.xml
file. Make a simple XSLT program to output the OOXML literally as it appears in the original word/document.xml
file. Then, slowly add in some customizations. When you are finished, reinsert the generated word/document.xml
file into the unzipped assembly, rezip, renaming the extension to .docx
and you'll have directly converted XML to DOCX as requested.
For further details, see Using XSLT and Open XML to Create a Word 2007 Document.
Upvotes: 4