xsl-list
[Top] [All Lists]

Re: Calling java in xsl.

2006-02-14 14:37:03
Michael Kay wrote:

<xsl:variable name="todayPlus" select="cal:add($today, 6, $offset)"/>

Now, what bothers me about this is the variable todayPlus which serves no purpose other than giving us an opportunity to call add. How can we avoid this useless call?


You're right to be bothered: if Saxon were executing this, it would decide
that the variable served no useful purpose, and wouldn't evaluate it. Even
if it were evaluated, the order of evaluation is not guaranteed.

Of course in XSLT 2.0 you can do this calculation within the language, so
the problem wouldn't arise. But if you do need to call extension functions
for their side-effects rather than their result, my usual advice is to use a
construct where the result appears to be used. In many cases the Java method
returns void, so (in Saxon at any rate) you can do

<xsl:sequence select="cal:add($today, 6, $offset)"/>

Thanks for that. Mainly for my own curiousity, how do we make this call directly in 2.0?



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>