954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using custom functions in j xslt with jaxp

Hi,

I need to call a public static method that returns in xslt. I'm using jstl to do the transformation and hence using the jaxp parser which would use XSLTC or Xalan internally.

The way I have the namespacee declaration for my xslt is

and in side the xslt I have

I get an error saying

XPST0017: XPath syntax error at char 39 on line 125 in {...etCategoryName('45.123...}

Cannot find a matching 1-argument function named
{http://xml.apache.org/xalan/java/com.csa.porter.scat.CategoryUtils}getCategoryName()

How can I successfully call anexternal custom java method from my xslt using jstl?

Thank you.

saraswathy6
Newbie Poster
5 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

You need to "include" your java class with that function in your XSLT. You can do this using the "xsl:script" instruction. Take a look below for more details.

http://saxon.sourceforge.net/saxon6.4.3/xsl-elements.html#xsl:script

The idea is that you point to the class and declare the prefix that the functions of that class will use.

<xsl:script language="java" implements-prefix="myUtil" src="java:java.util.Date" />


Something that that above. If you're having problems with the xsl:script instruction, look at processor specific methods. For example the saxon processor has a "saxon:script" instruction that does mostly the same thing. Your processor should have one.

iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

Hi,

Thank you for answer. I did solve the problem as you mentioned by

saraswathy6
Newbie Poster
5 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

Thank you for helpful answer. I did solve the problem as you mentioned by adding the script after the namespace declaration

However I got some errors on the console like

05:43:03,631 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #89; Column #78; org.apache.xpath.objects.XString
05:43:03,631 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #159; Column #40; org.apache.xpath.objects.XString
05:43:03,631 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #166; Column #40; org.apache.xpath.objects.XString
05:43:03,631 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #173; Column #40; org.apache.xpath.objects.XString
05:43:03,663 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #180; Column #40; org.apache.xpath.objects.XString
05:43:03,663 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #187; Column #40; org.apache.xpath.objects.XString
05:43:03,663 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #194; Column #40; org.apache.xpath.objects.XString
05:43:03,663 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #201; Column #40; org.apache.xpath.objects.XString
05:43:03,663 ERROR [STDERR] file:///C:/jboss-eap-4.3/jboss-as/bin/jstl:; Line #210; Column #40; org.apache.xpath.objects.XString

When I printed the xsl:version, xsl:vendor and xsl:vendor-url, I got

Version: 1.0
Vendor: Apache Software Foundation
Vendor URL: http://xml.apache.org/xalan-j

I need to use xslt 2.0 but Saxon 9 he does not support calling the java methods from the xslt directly.

Could you please help me in how I could use xslt 2.0 but still be able to call the java methods?

Thank you.
Saraswathy.

saraswathy6
Newbie Poster
5 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You