saxon-help

I'm looking for a solution to generate an identifier in a XQuery query. But
it seems that we cannot use XSLT functions in XQuery ( generate-id() ). Then
another solution would have to generate a ID with XQuery, for example by
using the Relations between the nodes: Parent, Children, Siblings,
Ancestors, Descendants; kind of : "count (preceding:: noeudx) +1" , but I
don't know how to write it properly.
I specify that the identifiers I want to generate should be affected in a variable so that I can use them in the query.
Thanks for help !!

I'd suggest writing a little Java module containing the method:
public static String generateId() {
FastStringBuffer buffer = new FastStringBuffer(16);
node.generateId(buffer);
return buffer.toString();
}
and then calling it as an extension function. (If the module is GenerateId
in package com.abc.gid, then you can call it as
declare namespace gid = "java:com.abc.gid.GenerateId;
gid:generate-id($node)
Michael Kay
http://www.saxonica.com/
_____
From: saxon-help-admin@...
[mailto:saxon-help-admin@...] On Behalf Of enis enis
Sent: 29 May 2006 10:11
To: saxon-help@...
Subject: [saxon] How to generate an Identifer in XQuery
I'm looking for a solution to generate an identifier in a XQuery query. But
it seems that we cannot use XSLT functions in XQuery ( generate-id() ). Then
another solution would have to generate a ID with XQuery, for example by
using the Relations between the nodes: Parent, Children, Siblings,
Ancestors, Descendants; kind of : "count (preceding:: noeudx) +1" , but I
don't know how to write it properly.
I specify that the identifiers I want to generate should be affected in a
variable so that I can use them in the query.
Thanks for help !!

enis enis write:
> Nothing is working for me ! :(
> String node = new String("noeud") ;
> NodeInfo myid = generateId(node);
But the goal is to have an extension function. So you don't have to
test it from Java, but from XQuery. To quote the response from
Michael:
and then calling it as an extension function. (If
the module is GenerateId in package com.abc.gid, then
you can call it as
declare namespace gid = "java:com.abc.gid.GenerateId;
gid:generate-id($node)
So try this:
(: I don't know the package of your class. :)
declare namespace mp = "java:MyProject";
let $node := /*[1]
return
mp:generate-id($node)
Just be sure your class is in the classpath.
I saw too that you import FastStringBuffer from a Xalan package. But
if you check the javadoc for NodeInfo, you'll see that the type of the
parameter of generateId() is net.sf.saxon.om.FastStringBuffer, so:
import net.sf.saxon.om.FastStringBuffer;
instead.
Regards,
--drkm
___________________________________________________________________________
Faites de Yahoo! votre page d'accueil sur le web pour retrouver directement vos services préférés : vérifiez vos nouveaux mails, lancez vos recherches et suivez l'actualité en temps réel.
Rendez-vous sur http://fr.yahoo.com/set

enis enis wrote:
> Then I added the path for pkg in the classpath : c:/saxon/pkg
If you read carefully the example, you see I add the current
directory (".") to the classpath, and the "pkg" directory is a child of
".". So add "c:/saxon" to your classpath, instead of "c:/saxon/pkg".
Regards,
--drkm
___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com

> Then I added the path for pkg in the classpath : c:/saxon/pkg
> If you read carefully the example, you see I add the current
>directory (".") to the classpath, and the "pkg" directory is a child of
>".". So add "c:/saxon" to your classpath, instead of "c:/saxon/pkg".
I added "c:/saxon" to the classpath but I have the same error !
"coudln't find a matching 1-argument fucntion named {java:pkg.GenerateId}generateId()"
so the problem is that it doesn't detect the path for the java class "GenerateId" maybe !
to execute the query I'm using a batch file like :
"rem set JAVA="C:\Program Files\Java\jdk1.5.0_07\bin\java"
set JAVA=java
rem modify the following line to set the classpath (saxon.jar)
set CP=-cp c:\saxon\saxon8.jar
%JAVA% %CP% net.sf.saxon.Query %1 %2 %3 %4 %5 %6 %7 %7"
so I execute it like :
c:\saxon>xquery -s test.xml -o sortie.xml test.xql

In your code the only thing you are putting on the classpath is the Saxon
code in saxon8.jar. You need to put your own Java class on the classpath
too.
Michael Kay
http://www.saxonica.com/
_____
From: saxon-help-admin@...
[mailto:saxon-help-admin@...] On Behalf Of enis enis
Sent: 01 June 2006 17:37
To: saxon-help@...
Subject: Re : [saxon] How to generate an Identifer in XQuery
> Then I added the path for pkg in the classpath : c:/saxon/pkg
> If you read carefully the example, you see I add the current
>directory (".") to the classpath, and the "pkg" directory is a child of
>".". So add "c:/saxon" to your classpath, instead of "c:/saxon/pkg".
I added "c:/saxon" to the classpath but I have the same error !
"coudln't find a matching 1-argument fucntion named
{java:pkg.GenerateId}generateId()"
so the problem is that it doesn't detect the path for the java class
"GenerateId" maybe !
to execute the query I'm using a batch file like :
"rem set JAVA="C:\Program Files\Java\jdk1.5.0_07\bin\java"
set JAVA=java
rem modify the following line to set the classpath (saxon.jar)
set CP=-cp c:\saxon\saxon8.jar
%JAVA% %CP% net.sf.saxon.Query %1 %2 %3 %4 %5 %6 %7 %7"
so I execute it like :
c:\saxon>xquery -s test.xml -o sortie.xml test.xql

Hi,
I've already tested many queries with Saxon succesfully, but today every query I want to process, it leads to the same error :
net.sf.saxon.trans.DynamicError : org.xml.XASParserException : Premature end of file.
Query processing failed : Run-time errors were reported
The execution is done by a command like :
c:/saxon> xquery -o books.xml -s sortie.xml query.xql
thanks for help !

The XML documents I'm using as input are the same ones that those I have tested before, so they are well-formed.
DIV { MARGIN:0px;} >This means that your input XML document isn't well-formed.
>Michael Kay
>http://www.saxonica.com/

I'm impressed by your confidence, but I'm more inclined to believe the error
message from the parser. If an XML parser says that it couldn't parse the
input file, it does so for a reason.
Michael Kay
http://www.saxonica.com/
_____
From: saxon-help-bounces@...
[mailto:saxon-help-bounces@...] On Behalf Of enis enis
Sent: 07 June 2006 10:35
To: Mailing list for SAXON XSLT queries
Subject: [saxon] Re : Error in execution of a query
The XML documents I'm using as input are the same ones that those I have
tested before, so they are well-formed.
>This means that your input XML document isn't well-formed.
>Michael Kay
>http://www.saxonica.com/