Help save net neutrality! Learn more.
Close

Saxon HE + XAR package

2010-05-11
2013-04-30
  • Florent Georges

    Florent Georges - 2010-05-11

      Hi,

      I've just created a set of classes to use XSLTHL with Saxon HE, which does not allow anymore calling Java methods directly from within the stylesheets.  You now have to create a function definition and a function call in Java.  I am not sure what's the best way to send you those files if you want them.  That's just a (very) quick code, but that should be a good start.

      I've also created a XAR package, which can be installed in an EXPath repository.  With this package, I was able to type:

    > xrepo install xslthl-2.1.0beta.xar
    Install module XSLTHL? [true]: 
    Install it to dir [xslthl]: 
    > saxon --java -Dxslthl.config=file:../highlighters/xslthl-config.xml -xsl:test-xslthl.xsl -it:main
    <?xml version="1.0" encoding="UTF-8"?>
             <xslthl:keyword xmlns:xslthl="http://xslthl.sf.net">public</xslthl:keyword> <xslthl:keyword xmlns:xslthl="http://xslthl.sf.net">class</xslthl:keyword> C { <xslthl:keyword xmlns:xslthl="http://xslthl.sf.net">public</xslthl:keyword> <xslthl:keyword xmlns:xslthl="http://xslthl.sf.net">void</xslthl:keyword> f() { } }
    

    with the following stylesheet (note there is no Java binding, only a namespace and a public import URI - the same stylesheet works with Saxon 9.0- also):

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:xslthl="http://xslthl.sf.net"
                    version="2.0">
       <xsl:import href="http://xslthl.sf.net/xslthl.xsl"/>
       <xsl:template match="/" name="main">
          <xsl:variable name="java">
             public class C { public void f() { } }
          </xsl:variable>
          <xsl:copy-of select="xslthl:highlight('java', $java)"/>
       </xsl:template>
    </xsl:stylesheet>
    

    If you want, I can send you those files as well.

      Regards,

     
  • Jirka Kosek

    Jirka Kosek - 2010-05-12

    Hi Florent,

    thanks for contribution. But first help me little bit to understand issue here. The code you have provided means that XSLTHL can be used with Saxon-HE but only when

    1. User also downloads EXPath packaging classes

    2. Uses EXPath class to run transformation instead of standard net.sf.saxon.Transform

    Am I right?

    Also what's the purpose of xsl:import here? (I haven't yet deeply studied new differences bethween HE, PE and EE regarding extensibility).

    Thanks,

    Jirka

     
  • Florent Georges

    Florent Georges - 2010-05-16

      Hi Jirka,

      Thanks for your response.  No, there are two orthogonal aspects here.  The documentation of XSLTHL, for now, only provides info using the Java mapping (with a URI like java:net.sf….).  This is not possible anymore with HE, which requires 2 Java classes per extension function, which describe them.  I've written such classes.  That's the first aspect.

      And in the same run, I've written a package which contains the JAR file and the package descriptor, conforming to the EXPath Packaging System.  This allows the user to automatically install the library in their repository, and use it consistently from everywhere in their computer (regardless on the location of the using stylesheets).  That's the second aspect.

      As per the import statement, it has nothing to do with the new integrated functions mechanism in Saxon 9.2.  This is a convention defined by the EXPath Packaging System.  When a stylesheet want to use external components (templates, functions, etc.) it has to use the corresponding xsl:import statement.  Regardless on whether the components are written in another stylesheet in the file system, or in a distant server but using catalogs, or as extension functions in another language.  This is not relevant.  Of course a processor is allowed to provide additional components in the static context (and the java: URI mapping is such a thing), but I think the spirit of the spec is more: you want to use a third-party library?, then use xsl:import to tell so to your processor.

      But well, this last paragraph is just a parenthese :-)  Do you want me to send those files?  If yes, what's the best way to do so?

      Cheers,

     
  • Jirka Kosek

    Jirka Kosek - 2012-07-28

    Hi Florent,

    this message slipped through my attention. Please could you send code dealing with Saxon HE integration? I have recently written some code for HE, so I might better understood to issues for now :-)

    Many thanks,

    Jirka

     
  • Nobody/Anonymous

    Is XSLTHL working with Saxon-HE yet? I would very much like to add syntax highlighting to my DITA documentation which is compiled using XML Mind Ditac.

     

Log in to post a comment.