Richard R. McKinley wrote:

I am defining a varible through the following method so that I keep the dependability of functional programming. Notice how I start by cloning an object and I never modify that object which is assigned to a variable. I don't want side effects:
<xsl:variable name="selected-month">
<xsl:variable name="selected-month" select="java:clone($calendar)"/>
<xsl:if test="java:set($selected-month, $date-field-value, 1)"/>
<xsl:if test="java:add($selected-month, $month-field-value, $month-offset)"/>
<xsl:value-of select="$selected-month"/>
</xsl:variable>


So, while I manipulate the value of the internal variable, it is only used to temporarily define the final outcome. However, <xsl:value-of> is not doing the same thing that <xsl:variable select=""/> would do. My variable is not getting a Java object assigned. When I later try to reference it for example:
<xsl:value-of select="java:get($selected-month, $month-field-value)"/>

You have two variables named "selected-month". The outer one of type result-tree-fragment (and not Calendar as you may expect) and the inner one of type Calendar. Avoid defining variables without a select attribute, or you'd get a result-tree-fragment.


Also note that your last value-of is likely to be calling toString() (at least XSLTC used to do that, can anyone confirm that this is what Xalan does also?) on the Calendar; thus converting the Calendar into a String (which is not what you intend, I believe). I think your making your life more difficult :-). Just create the instance and call the methods without using an outer variable.

Hope this helps.

-- Santiago




Reply via email to