ZIP Facility

Taps and pipes

This module is still a work in progress. An implementation exists for Saxon, but the specification has not been written yet, and there is almost no documentation. An introduction to EXPath, presented at Balisage in August 2009 contains examples, see the proceedings and the materials page. Any help, comment or suggestion greatly appreciated on the mailing list.

Prototype for Saxon

The current implementation for Saxon is provided as a XAR package: expath-zip-saxon-0.1.xar. You can use this package with the Packaging System, or just open it as a ZIP file, get the JAR file within it, and set your Saxon processor up (especially the classpath). Here is an complete example (provided you correctly installed the package in your repository, you can just save it in a file and execute it with saxon -xsl:zip-list.xsl -it=main file=.../some/file.zip):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                xmlns:zip="http://www.expath.org/mod/zip"
                version="2.0">
   
   <xsl:import href="http://expath.org/ns/zip.xsl"/>
   
   <xsl:output indent="yes"/>
   
   <!--
      $file is the ZIP file to use.  If $entry is set, extract that
      entry from $file, as an XML document.  If not, list the content
      of $file.
   -->
   <xsl:param name="file"  as="xs:string"/>
   <xsl:param name="entry" as="xs:string?"/>
   
   <xsl:template name="main" match="/">
      <xsl:choose>
         <xsl:when test="$entry">
            <!-- an XML entry in the ZIP file -->
            <xsl:sequence select="zip:xml-entry($file, $entry)"/>
         </xsl:when>
         <xsl:otherwise>
            <!-- the structure of the ZIP file -->
            <xsl:sequence select="zip:entries($file)"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
</xsl:stylesheet>