Directly convert a single XML file to DOCX

99封情书 提交于 2020-07-07 06:34:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/38298174/directly-convert-a-single-xml-file-to-docx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!