Menu

Writing extensions in Java

2008-04-30
2012-10-08
  • Michael Hare

    Michael Hare - 2008-04-30

    I tried a dirt simple example.

    package com.fujitsu.fnc.swda.extensions;

    public class functions {

    /**
     * constructor
     */
    private functions () {
    
    }
    
    /**
     * test function
     * @return
     */
    public static int test() {
        return 35;
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(test());
    }
    

    }

    I copied the resulting .class file to my CLASSPATH
    and I used this to call it:

    <xsl:text>#x0A;</xsl:text>
    <xsl:text>Testing Processor Extensions</xsl:text>
    <xsl:text>#x0A;</xsl:text>
    <xsl:value-of select="swda:test()" xmlns:swda="java:com.fujitsu.fnc.swda.extensions.functions">
    </xsl:value-of>

    Only I get a

    quote:SystemID: D:\mphare\Development\XMLTesting\extensions\test.xsl
    Location: 20:0
    Description: XPath syntax error at char 11 on line 20 in {swda:test()}:
        Cannot find a matching 0-argument function named {java:com.fujitsu.fnc.swda.extensions.functions}test()
    URL: http://www.w3.org/TR/xpath20/#ERRXPST0003
    

    I believe Michael Kay has pointed me in the right direction (and to this forum :)) by suggesting the CLASSPATH is ignored because I just a command line like:

    java -jar C:\Programs\saxon\saxon8.jar

    to get execute the processor.

    Problem is, I'm not sure how to fix it.

    Thanks,

    • m

    GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

    Michael Hare

     
    • Michael Kay

      Michael Kay - 2008-04-30
       
    • Michael Hare

      Michael Hare - 2008-04-30

      Thanks Michael,

      I'm getting a DNS Error on saxonica this morning, I'll try again a littler later, maybe a router is down somewhere.

       
    • Michael Hare

      Michael Hare - 2008-04-30

      So far so good.
      The extension is working and doing what I expected it to do.. which is not much, but it's doing it.

      Thanks!

      • m