You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Cameron McCormack <cl...@csse.monash.edu.au> on 2003/06/17 12:36:34 UTC

Extending XPath with some functions

Hi everyone.

I'd like to use Xalan's XPath implementation with SVG documents loaded
by Batik (which, I assume, uses Xerces).  I would like, though, to have
some extra functions available in the XPath expressions, which act just
like the core XPath functions.

I notice on this[1] page an example Java class called MyCounter.  This
is then used in the XSLT stylesheet with the xalan:component element.
Now, since I don't have an XSLT document, just an SVG document (to which
I don't want to add any extension function looking things (like
xalan:component, a different namespace)) I don't know how to register a
class which has extension XPath functions in it with the XPath
implementation.  I'm guessing it somehow needs to be given to the
XPathContext that each XPath will use.

But how exactly do I do that?

Thanks,

Cameron

[1] http://xml.apache.org/xalan-j/extensions.html

-- 
Cameron McCormack
  // clm@csse.monash.edu.au
  // http://www.csse.monash.edu.au/~clm/
  // icq 26955922

Re: Extending XPath with some functions

Posted by Cameron McCormack <cl...@csse.monash.edu.au>.
Hi Joaquín.

Joaquín Sánchez Jiménez:
> Make your function class that must extends from org.apache.xpath.Expresion
> or some child and then include it use
> org.apache.xpath.compiler.FunctionTable.installFunction(String name,
> org.apache.xpath.Expresion exp);

Thanks, that looks like just what I was after.

Cameron

-- 
Cameron McCormack
  // clm@csse.monash.edu.au
  // http://www.csse.monash.edu.au/~clm/
  // icq 26955922

Re: Extending XPath with some functions

Posted by Joaquín Sánchez Jiménez <Jo...@fi2net.com>.
Hi:

> I'd like to use Xalan's XPath implementation with SVG documents loaded
> by Batik (which, I assume, uses Xerces).  I would like, though, to have
> some extra functions available in the XPath expressions, which act just
> like the core XPath functions.

Make your function class that must extends from org.apache.xpath.Expresion
or some child and then include it use
org.apache.xpath.compiler.FunctionTable.installFunction(String name,
org.apache.xpath.Expresion exp);

You can see org.apache.xpath.functions package to see how it works. I have
implemented some extensions like equals_ignore_case, stop counters, xml
result paging and some more.

Then in your XSL file you can call your built-in function.

I found in source it is limited to 30 built-in functions.

Bye.

----- Original Message -----
From: "Cameron McCormack" <cl...@csse.monash.edu.au>
To: <xa...@xml.apache.org>
Sent: Tuesday, June 17, 2003 12:36 PM
Subject: Extending XPath with some functions


> Hi everyone.
>
> I'd like to use Xalan's XPath implementation with SVG documents loaded
> by Batik (which, I assume, uses Xerces).  I would like, though, to have
> some extra functions available in the XPath expressions, which act just
> like the core XPath functions.
>
> I notice on this[1] page an example Java class called MyCounter.  This
> is then used in the XSLT stylesheet with the xalan:component element.
> Now, since I don't have an XSLT document, just an SVG document (to which
> I don't want to add any extension function looking things (like
> xalan:component, a different namespace)) I don't know how to register a
> class which has extension XPath functions in it with the XPath
> implementation.  I'm guessing it somehow needs to be given to the
> XPathContext that each XPath will use.
>
> But how exactly do I do that?
>
> Thanks,
>
> Cameron
>
> [1] http://xml.apache.org/xalan-j/extensions.html
>
> --
> Cameron McCormack
>   // clm@csse.monash.edu.au
>   // http://www.csse.monash.edu.au/~clm/
>   // icq 26955922
>