我通过生成XSLT样式表解决了这个问题,该样式表将ODT源文件转换为与标准“或多或少”兼容的XML文件。以下是代码。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
<xsl:param name="meta.file" select="'meta.xml'" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="office:document-content">
<office:document>
<xsl:copy-of select="@*" />
<xsl:variable name="meta" select="document($meta.file)/office:document-meta/office:meta" />
<xsl:copy-of select="$meta" />
<xsl:apply-templates />
</office:document>
</xsl:template>
</xsl:stylesheet>
然后你可以用文本编辑器打开这个文件,或者只是使用cat,你会看到格式化的xml源文件。 –
你确定有一种方法可以和LibreOffice做到这一点吗?我没有在任何地方看到“Flat ODT”。 –
@StéphaneLaurent:是LibreOffice支持Flat ODT文件。例如[3.4版发布说明](https://wiki.documentfoundation.org/ReleaseNotes/3.4)说:“重写扁平ODF导入和导出文件过滤器,从Java到C++,从而大大提高速度”。 – gioele