3

I have this xslt file that I need to call a java function placed somewhere else in the same application. In the xslt file I have

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:java="java" 
                xmlns:test_my="vobs.plugins.WikiParser.WikiParser"
                version="2.0">
  <xsl:output indent="yes" method="html"/>
  <xsl:template match="/">
    <H1>
      <xsl:value-of select="WikiDescription/Title"/>
    </H1>
    Summary: <xsl:value-of select="WikiDescription/Description"/>
    <xsl:variable name="text">                      
      <xsl:value-of select="WikiDescription/Text"/>
    </xsl:variable>
    <p>
      <xsl:value-of select="test_my:parse2($text)" 
                    disable-output-escaping="yes"/>
    </p>

but when I try to excute this xlst file I got the following error

XSL transform reported error: 
XPath syntax error at char 21 on line -1 in {test_my:parse2($text)}: 
Cannot find a matching 1-argument function named 
{vobs.plugins.WikiParser.WikiParser}parse2()

it seems like that it couldn't find the java class, so what's the right way to do this? some code example will be even better. Thanks in advance!

1
  • Took another look at my XSLs. It seems that what worked for me is using "urn:java:" before the fully qualified name of the class (as opposed to my earlier post where I just used "java:"). Updated my answer accordingly. Let me know if it works for you. Commented Oct 12, 2011 at 20:02

3 Answers 3

3

I had exactly the same problem and this solved it for me where urn:java: and java: both failed.

Assuming you're using Xalan to do the transformation, you should change xmlns:test_my="vobs.plugins.WikiParser.WikiParser" to xmlns:test_my="xalan://vobs.plugins.WikiParser.WikiParser".

Sign up to request clarification or add additional context in comments.

Comments

3

It depends on what XSLT transformation processor you are using. Saxon uses urn:java:; Xalan uses xalan://.

Comments

2

You need to change the namespace declaration (at the xsl:stylesheet element) from xmlns:test_my="vobs.plugins.WikiParser.WikiParser" to xmlns:test_my="urn:java:vobs.plugins.WikiParser.WikiParser"

The rationale is as follows: In order to use a class C from package a.b you need to define a namespace prefix and associate it with the urn:java:a.b.C.

If I understand XSL correctly the urn: prefix is needed when importing Java code that is not part of the standard library (as in your case). If you only need to import standard library classes then "java:" will do.

(Further details: http://cafeconleche.org/books/xmljava/chapters/ch17s03.html)

[EDIT: change "java:" -> "urn:java:"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.