直接将单个XML文件转换为DOCX [英] Directly convert a single XML file to DOCX

查看:123
本文介绍了直接将单个XML文件转换为DOCX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将单个XML文件转换为DOCX文件,然后通过使用XSLT将XML转换为XHTML来实现,然后在MS Word上打开XHTML并将其另存为DOCX.

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.

但是我的任务是将任何XML结构(DITA,TEI,DocBook等)直接转换为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?

我只是找不到任何来源.始终是DOCX到XML,而不是相反.

I just can't find any sources for this. It's always DOCX to XML and not the other way around.

推荐答案

是的,您可以使用XSLT从任何这些XML格式转换为

Yes, you can use XSLT to transform from any of those XML formats to OOXML. XSLT is ideal for XML to XML transformations.

也就是说,您提到的每种输入XML格式都非常复杂,而OOXML则非常复杂.此外,DOCX实际上是许多组件的集合,包括OOXML中的 document.xml 文件,该文件通过

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.

首先,建议您以创建一个首先在MS Word中手动创建的简单文档为目标.将文件从 .docx 扩展名重命名为 .zip 扩展名,并解压缩组件并恢复 word/document.xml 文件.制作一个简单的XSLT程序,以按原样输出OOXML,该OOXML出现在原始 word/document.xml 文件中.然后,慢慢添加一些自定义项.完成后,将生成的 word/document.xml 文件重新插入解压缩的程序集中,重新压缩,将扩展名重命名为 .docx ,您将直接将XML转换为DOCX根据要求.

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.

有关更多详细信息,请参见使用XSLT并打开XML以创建Word 2007文档.

For further details, see Using XSLT and Open XML to Create a Word 2007 Document.

这篇关于直接将单个XML文件转换为DOCX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆