我通過生成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