xsltantods

Manipulating an OpenDocument Sheet (.ods) with pure Apache Ant and XSLT


I'd like to create a very simple ODS file with pure Apache Ant and XSLT. My idea is to basically unzip an empty ODS file, run some XSLT on the included content.xml file and zip everything again afterwards. My code works, but the ODS file is invalid, when I validate it with odfvalidator.org.

The document is NOT conformant ODF1.3!

Details:
export.ods: Info: ODF version of root document: 1.3
export.ods/mimetype: Error: There shall be no extra field for the 'mimetype' file of ODF package 'export.ods'!
export.ods/mimetype: Error: The file 'mimetype' is not the first file in the ODF package 'export.ods'!
internal:/schema/odf1.3/OpenDocument-v1.3-manifest-schema.rng: Info: parsed.
export.ods/META-INF/manifest.xml[2,88]: Error: element "manifest:manifest" is missing "version" attribute
es:tc:opendocument:xmlns:manifest:1.0"><manifest:file-entry manifest:full-path= ----^ export.ods/META-INF/manifest.xml: Info: 1 errors, no warnings
export.ods/mimetype: Info: 2 errors, no warnings
export.ods: Info: Media Type: application/vnd.oasis.opendocument.spreadsheet
internal:/schema/odf1.3/OpenDocument-v1.3-schema.rng: Info: parsed.
export.ods/meta.xml: Info: Generator: MicrosoftOffice/16.0 MicrosoftExcel/CalculationVersion-26731
export.ods/meta.xml: Info: no errors, no warnings
export.ods/styles.xml: Info: no errors, no warnings
export.ods/content.xml: Info: no errors, no warnings
internal:/schema/odf1.3/OpenDocument-v1.3-dsig-schema.rng: Info: parsed.
export.ods: Info: 3 errors, no warnings

I do not understand the problem, to be honest. What does this mean:

The file 'mimetype' is not the first file in the ODF package

How can a file be the first file in a ZIP archive (the ODS file is a ZIP file)?

The <zip> task in my Ant target looks like this:

<zip destfile="${ods-export.temp.dir}${file.separator}export.ods" basedir="${ods.dir}" compress="false"/>

I'd like to avoid using Java completely to keep the complexity low. I've found the odftoolkit.org project, which could be used for a Java-based solution, but as I said, I'd like to avoid that.


Solution

  • Fortunately it was easier as expected. Originally, I created an empty ODS file with Microsoft Excel. This did not work with my approach. But when I create an empty ODS file with LibreOffice, it works perfectly.