Hi,

I followed all the steps you wrote.
my current directory : saxon;
my package : saxon/pkg (contains GenerateId.java and GenerateId.class)
query : source/test.xql
source : source/test.xml
Then I added the path for pkg in the classpath : c:/saxon/pkg

Test.xql :
declare namespace gi = "java:pkg.GenerateId";
    let $node := /*[1]
    return
    <id>  {   gi:generateId($node) }
    </id>
 
I get an error : coudln't find a matching 1-argument fucntion named {
java:pkg.GenerateId}generateId()


Enis

----- Message d'origine ----
De : Florent Georges <darkman_spam@yahoo.fr>
À : saxon-help@lists.sourceforge.net
Envoyé le : Jeudi, 1 Juin 2006, 2h56mn 28s
Objet : RE: Re : Re : Re : [saxon] How to generate an Identifer in XQuery

enis enis wrote:

  Hi

> If I understood well, I have to write :

> [...]

> but I'm not sure about how to write it, compile it,
> declare it and call it from the query file. Things are
> mixed in my mind !

  Maybe the discussion in getting a little bit OT, because
we are speaking of Java basis, IMHO.  But I think it may be
interesting to have such an all-steps-explained message on
the archive of the list.

    > cat pkg/GenerateId.java
    package pkg;

    import net.sf.saxon.om.FastStringBuffer;
    import net.sf.saxon.om.NodeInfo;

    public class GenerateId
    {
        public static String generateId(NodeInfo node) {
            FastStringBuffer buffer = new FastStringBuffer(16);
            node.generateId(buffer);
            return buffer.toString();
        }
    }

    > cat test.xq
    declare namespace gi = "java:pkg.GenerateId";
    let $node := /*[1]
      return
        <id>{ gi:generateId($node) }</id>

    > cat test.xml
    <root>
      <elem/>
    </root>

    > javac -cp "path/to/saxon8.jar" pkg/GenerateId.java

    > java -cp ".;path/to/saxon8.jar" net.sf.saxon.Query \
          -s test.xml test.xq
    <?xml version="1.0" encoding="UTF-8"?>
    <id>d0e1</id>

  So two things in addition to the usual Java things:

    1/ your extension class has to be in the classpath when
       you invoque Saxon;

    2/ in your query, you declare a namespace whose the URI
       is "java:<your.class.name>", then you access the
       methods by using the prefix, and the method name as
       the local part.

  See the Saxon documentation for further info:

    http://saxonica.com/documentation/extensibility/functions.html

  At the bottom, you have three links:

    - Calling Static Methods in a Java Class
    - Calling Java Constructors
    - Calling Java Instance-Level Methods

  Regards,

--drkm



























    

    
        
___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
saxon-help mailing list
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help