0
votes

Apparently, it is impossible to directly call an external function from xsl:apply-templates. I have an XML node containing html tag for example :

<text>
    <ul>
        <li>
            blablablaba
        </li>
    </ul>
<text>  

In my output, if I want the html tags to be applied, I need to use xsl:apply-templates select="text"/>. I can't use xsl:value-of since it won't consider the HTML. Now the problem is that I need to call a function which will transform the html tags so my code would be :

<xsl:apply-templates select="util:myFunction(text)"/>

However, this will result in an error, is there another way I could do this ?

Thanks in advance.

1
Well, XSLT is already for transformation. What can it not do, what do you want it to do for you? Why do you need a Java function to do transformation while you are already using a tool meant for transformation? A little explanation on the problem would help in understanding your problem. Maybe XSLT is simply not right for you? - ppeterka
[1] Do you declare the util: namespace as a java class ? [2] How are you calling xslt ? Do you include the jar with that class on the command line ? - Steven D. Majewski
How does the function code look? If you want to have the XSLT processor interact with Java and process the result of a function call into Java with apply-templates you need to be familiar with the API of the particular XSLT processor you use so that your function returns objects of the type or class or interface the XSLT processor consumes as nodes. - Martin Honnen
It is not a call problem because when I try calling it with xsl:value-of select="myFunction()"/> it works. Also, the function code works when it's called with value-of. - Jean-François Savard

1 Answers

1
votes

I think what you are trying to say is: it appears to be impossible to use a function call to a Java function returning a string, in a context where XSLT requires an XPath expression which evaluates to a set of nodes.

Yes, that's impossible.

If you want to use the call util:myFunction(text) to select the nodes to which templates should be applied, you will need that function to return a set of nodes using whatever tree representation your XSLT processor is using.

It is almost certainly possible to do this, for XSLT processors that support user-supplied Java functions at all. It is also almost certainly not the best solution for selecting input nodes to process; it's hard to imagine any node selection process that is easier in Java than in XSLT.