Reputation: 11065
I know I can assign the value of a returning function to a variable in xslt the following way:
<xsl:variable name="var" select="myClass:function1()"/>
But I want to call a void function, the above syntax though still works, is there a better or cleaner way to do that?
Upvotes: 2
Views: 1029
Reputation: 163587
The interface from XSLT to Java is not standardized; it depends on which XSLT processor you are using, so you need to include this information in your question. (Actually, you don't even say if you are using Java; I kind of assumed this from context).
In Saxon, calling functions with side-effects within xsl:variable is definitely not recommended, because variables are evaluated lazily, so you have no control over the order of evaluation, and if the variable is never referenced then it won't be evaluated at all. If you must call a function with side-effects, it's best to do it in an xsl:value-of instruction, at a point where if the function did return a value, that value would be added to the result tree. (The Saxon optimizer goes out of its way not to use the knowledge that the function never returns anything, which would normally result in it not being called.)
Upvotes: 5