[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Zipping xsl:result-documents into ePub


Subject: Re: [xsl] Zipping xsl:result-documents into ePub
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Tue, 25 Aug 2009 15:05:47 +0000 (GMT)

Martynas Jusevicius wrote:

  Hi,

> However, so far I'm writing the result
documents to a folder in
> the filesystem.  As I'm planing to package them
into ePub file
> using java.util.zip, this is probably not very smart.  Is
there
> a way to avoid serializing to files and pass the result
> documents
directly to java.util.zip, probably as streams?  I
> saw OutputURIResolver
mentioned, but couldn't find a decent
> example.

  You can also have a look
at the EXPath ZIP facility.  It has
not been released yet, and is still in
development, but if you
generate (at least some of) the entries of the ZIP
file in XSLT,
it allows you to handle the creation of the ZIP file directly
from the stylesheet.  See a complete example at the end of this
message.

  As
I said, it has not been released yet, but you can find a dev
version at
http://www.expath.org/tmp/expath-zip-saxon-0.1.pkg.zip
for Saxon.  Just import
the included stylesheet in your own
stylesheet and put the JAR file into your
classpath.

  For any further info, see http://groups.google.com/group/expath
and http://www.expath.org/.

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:zip="http://www.expath.org/mod/zip"
xmlns="urn:oasis:names:tc:opendocument:xmlns:container"
exclude-result-prefixes="#all"
                version="2.0">

   <xsl:import
href="http://www.expath.org/mod/zip.xsl"/>

   <xsl:output
omit-xml-declaration="yes" indent="yes"/>

   <xsl:template name="main"
match="/">

      <!-- the output file name -->
      <xsl:variable
name="file" select="
          resolve-uri('simple-zip-create.zip')"/>
<!-- description of the content of the new ZIP file -->
      <xsl:variable
name="struct" as="element(zip:file)">
         <!-- the ZIP file itself -->
<zip:file href="{ $file }">
            <!-- the 'mimetype' file within the
ZIP -->
            <zip:entry name="mimetype" output="text">
<xsl:text>application/epub+zip</xsl:text>
            </zip:entry>
<!-- the 'META-INF' dir within the ZIP -->
            <zip:dir
name="META-INF">
               <!-- the 'container.xml' file within the dir
-->
               <zip:entry name="container.xml" output="xml">
<container version="1.0">
                     <rootfiles>
<rootfile full-path="..." media-type="..."/>
                     </rootfiles>
</container>
               </zip:entry>
            </zip:dir>
</zip:file>
      </xsl:variable>

      <!-- the entries in the presentation
file -->
      <xsl:sequence select="zip:zip-file($struct)"/>
</xsl:template>

</xsl:stylesheet>


Current Thread
Keywords