An unzip extension step for XML Calabash that unzips entire archives.
XProc 1.0 lacks of a native unzip solution. Therefore, XProc processors such as XML Calabash or Morgana provide own extension steps for extracting zip archives. However, these steps allow only to extract XML files in an archive. To extract other file types, we've developed this unzip-extension step for XML calabash. It extracts all files to the specified location and provides an XML data set as output.
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:tr="http://transpect.io"
version="1.0">
<p:output port="result"/>
<p:import href="http://transpect.io/calabash-extensions/unzip-extension/unzip-declaration.xpl"/>
<tr:unzip name="unzip">
<p:with-option name="zip" select="'archive.zip'"/>
<p:with-option name="dest-dir" select="'file:/C:/home/kraetke/output'"/>
<p:with-option name="overwrite" select="'no'"/>
</tr:unzip>
</p:declare-step>
The output would look somewhat like this:
<?xml version="1.0" encoding="UTF-8"?>
<c:files xmlns:c="http://www.w3.org/ns/xproc-step"
xml:base="file:/C:/home/kraetke/output">
<c:file name="dir/myfile.xml"/>
</c:files>
Java 1.7
- Add the unzip-extension to your XML Calabash
$XPROC-CONFIG
file
<?xml version="1.0" encoding="UTF-8"?>
<xproc-config xmlns="http://xmlcalabash.com/ns/configuration"
xmlns:tr="http://transpect.io"
xmlns:tr-internal="http://transpect.io/internal">
<implementation type="tr-internal:unzip" class-name="io.transpect.calabash.extensions.UnZip"/>
</xproc-config>
- Add
io/transpect/calabash/extensions/UnZip.class
to your Java$CLASSPATH
(otherwise XML Calabash will fail with a class not found error) - Connect
xmlcatalog/catalog.xml
with your$XMLCATALOG
vianextCatalog
statement or just pass‑Dxml.catalog.files=xmlcatalog/catalog.xml
as parameter to Java - Run XML Calabash
java \
-cp "$CLASSPATH" \
-Dfile.encoding=UTF-8 \
-Dxml.catalog.files=$XMLCATALOG \
-Dxml.catalog.staticCatalog=1 \
com.xmlcalabash.drivers.Main \
-Xtransparent-json \
-E org.xmlresolver.Resolver \
-U org.xmlresolver.Resolver \
-c $XPROC-CONFIG \
unzip-example.xpl \
zip=myarchive.zip \
path=output
We already provide a class file and a jar file, but feel free to compile this extension for your needs.
- add the jars of XML Calabash and Saxon to your Java
$CLASSPATH
- compile it
javac -source 1.7 -target 1.7 -d . -cp $CLASSPATH src/main/java/io/transpect/calabash/extensions/UnZip.java