You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Chris P. McCabe" <ch...@choicehotels.com> on 2001/03/23 00:47:37 UTC

Question about calling a Java method with no result

I want to call a Java method on an object from within a stylesheet, but
the method does not return a value - it modifies the object instead.  So
I just assign it to a bogus variable to get it to call the method
anyway.  This worked OK in Xalan-J1, and works in Xalan-J2 *if* the
variable is defined within a template, but if it is global, the bogus
variable never gets evaluated because it is never referenced, so the
method never gets called.

Here is an example:

Assume $date contains a java.util.Date object, and $cal contains a
java.util.Calendar object.  If I want to set the Calendar to the value
of the date, I can do:

<xsl:variable name="bogus" select="java:setTime($cal, $date)"/>

This simply modifes the $cal object, but does not actually return
anything.  If this is done at the top level of the stylesheet, it is
never called, presumably because $bogus is never referenced.  I presume
I could do something like <xsl:value-of select="$bogus"/> somewhere in
the stylesheet, but what if the method actually does return something
that I would prefer to ignore?

Is there another way to call a method like this other than the hack of
setting a bogus variable?  Am I correct in assuming it is due to lazy
evaluation (and no reference to the bogus variable) that the method is
not called?

Thanks,
Chris