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

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:autn="http://schemas.autonomy.com/aci/" xmlns:myUtil="http://xml.apache.org/xalan/java/com.csa.porter.scat.CategoryUtils" xmlns:java="http://xml.apache.org/xalan/java"
exclude-result-prefixes="myUtil java">

and in side the xslt I have <xsl:value-of select="myUtil:getCategoryName('45.123')"/>

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.

Recommended Answers

All 3 Replies

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.

Hi,

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

Hi,

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

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:autn="http://schemas.autonomy.com/aci/" xmlns:xalan="http://xml.apache.org/xalan" xmlns:myUtil="http://xml.apache.org/xalan/java/com.csa.porter.scat.CategoryUtils" extension-element-prefixes=" myUtil" xmlns:java="http://xml.apache.org/xalan/java"
exclude-result-prefixes="myUtil java">
<xalan:script lang="javaclass" src="java:com.csa.porter.scat.CategoryUtils" />

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.