Sunday, November 15, 2009

EXPath Packaging System prototype implementation for Calabash

An interesting piece of code I worked on during the past few weeks is the implementation of the EXPath Packaging System for the Norman Walsh's XProc processor: Calabash. It was interesting for itself, as a coding experience, but also for the still-in-development packaging system, as XProc provides all core XML technologies within a single language. Thus implementing the packaging system for Calabash implied to implement it for: RNC, RNG, Schematron, XProc (for XProc pipelines themselves,) XQuery, XSD and XSLT. This was enlightening about the relationships between those several technologies, and a proof of concept about the applicability of the packaging concept to those several technologies.

Unfortunately, Calabash does not provide any way for the user to finely configure the underlying processors (for instance Saxon for XSLT, Jing for RNG, etc.) So I first needed to add this feature to Calabash itself. Instead of plugging the EXPath stuff directly into the Calabash code base, I decided to add only a simple API for an external user to plug configuration code into Calabash. I hope Norm will agree on integrating such changes into Calabash, so the packaging support could be written entirely outside of the Calabash code base in a first time (and maybe included in Calabash in a second time.) In the meanwhile, you can just use an alternative JAR file for Calabash, including my changes (and based on the latest Subversion revision, so this is really beta stuff, besides some classes have been disabled also, due to dependency issues.) You can also have a look at the following email on XProc Dev with explanations on how to patch the Calabash code base.

To install the packaging support for Calabash, you need to put the following JAR files into your classpath: my modified Calabash JAR file, the EXPath repository management, the EXPath packaging support for Calabash and the EXPath packaging support for Saxon. Then run Calabash the usual way, besides setting the Java property org.expath.pkg.calabash.repo to the location of the repository you want to use. For repository management, please see the next blog entry I will post here...

If you are under Unix (incl. Linux, Mac OS X or Cygwin under Windows) you can use this shell script to launch Calabash from the command line. Just define the environment variable CALABASH_CP with the above classpath, and EXPATH_REPO to the repository directory. In addition to setting Calabash up, it will also add JAR files with extensions for Saxon into the classpath.

To test if the installation is ok, install this sample package (wait for the next blog entry for details about installing a package with the repository) and save the following pipeline in a file, say invoice-test.xproc:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:i="http://www.fgeorges.org/test/invoice-steps">

   <p:import href="http://www.fgeorges.org/test/invoice.xpl"/>

   <p:output port="result"/>

   <p:input port="source">
      <p:inline>
         <invoice xmlns="http://www.fgeorges.org/test/invoice"
                  date="2009-10-12">
            <line price="15" quantity="10" unitary="1.5">
               <desc>Some stuff.</desc>
            </line>
            <line price="100">
               <desc>Bigger stuff.</desc>
            </line>
            <total tax-excl="115" tax-incl="139.15"/>
         </invoice>
      </p:inline>
   </p:input>

   <i:validate/>

   <i:transform/>

</p:declare-step>

Then run it using the above description. If you saved the shell script under the name "calabash" in your $PATH, just type:

calabash invoice-test.xproc

And that's all! See the EXPath Packaging page for more information, and subscribe to the EXPath mailing list to stay tunned.

Labels: ,

0 Comments:

Post a Comment

<< Home