Project

Profile

Help

Calls to void functions are ignored

Added by Anonymous almost 14 years ago

Legacy ID: #8520941 Legacy Poster: https://www.google.com/accounts ()

When calling a Java extension function, it seems that calls to void functions are ignored by Saxon when the function call is wrapped by an XSL variable like such: [code] <xsl:variable name="xx" select="ab:setString($ab,'StringName', NodeValue)"/>[/code] However, the function is invoked if this is changed to: [code] <xsl:value-of select="ab:setString($ab,'StringName', NodeValue)"/>[/code] I did find some others having similar issues. [url]http://stackoverflow.com/questions/2631301/cannot-access-updated-java-object-from-saxon-xslt-processor[/url] I am noticing similar behavior with the "document()" function in Saxon as well. Any insight would be appreciated. Thanks.


Replies (3)

Please register to reply

RE: Calls to void functions are ignored - Added by Anonymous almost 14 years ago

Legacy ID: #8521265 Legacy Poster: Michael Kay (mhkay)

It's nothing to do with the function being void: variables are evaluated on first reference, so if you declare a variable but don't use it, Saxon never evaluates the variable and therefore never calls the function. The advice is to avoid functions with side-effects if you can. But if you can't, you need to use them in such a way that the logic of the stylesheet at least appears to use the function's result.

RE: Calls to void functions are ignored - Added by Anonymous almost 14 years ago

Legacy ID: #8522705 Legacy Poster: https://www.google.com/accounts ()

Thank you for your response. Is there an alternate syntax that can be used, that guarantees that the function is invoked? Thanks.

RE: Calls to void functions are ignored - Added by Anonymous almost 14 years ago

Legacy ID: #8524719 Legacy Poster: Michael Kay (mhkay)

There's no purely syntactic remedy, for example calling the function within xsl:value-of would do no good if the xsl:value-of instruction itself is not executed. But you can apply this test: if there's a location in your stylesheet where xsl:textHi!</xsl:text> would cause the string Hi! to be written to the final result tree, then a call to <xsl:sequence select="f:void-function()"/> in the same position will cause the function to be invoked. Similarly if you take two instructions xsl:textHello</xsl:text> and xsl:textWorld</xsl:text> and replace them both with function calls, then if the order of the output would have been Hello followed by World, you also have (for the current release at any rate) a guarantee that the two function calls will occur in the "right" order. In general though I would emphasize that calling functions with side-effects is something to avoid if you can.

    (1-3/3)

    Please register to reply