On 30 Sep 2013, at 11:43, PLACAIS Laurent wrote:
<xsl:variable name="countField1" select="jav:add($countField, '1')"/>
This variable is never referenced, so it is never evaluated. You can write calls to Java methods that have side-effects like this, but you need to be very careful that the optimizer doesn't optimize them away. If you want to call a method that returns no result, the safest way is to do it in an xsl:value-of instruction, at a point where the result (if there was a result) would be written to the result tree.
If you're causing side-effects, then you also need to be sure that instructions are executed in the right order. The only foolproof way to do that is to create a functional dependency, but in practice, you can usually rely on the fact that instructions which (appear to) write to the result tree are executed in the order of the result tree nodes they are writing.
I think you could write this as:
<xsl:value-of name="countField1" select="jav:add($countField, '1')"/>
<xsl:attribute name="Name"><xsl:text>Media</xsl:text></xsl:attribute> <xsl:attribute name="Status"><xsl:text>2</xsl:text></xsl:attribute> <xsl:attribute name="Count"><xsl:value-of select="jav:size($countField)"/></xsl:attribute> <xsl:copy-of select="$Fields"/>
However, there is probably a better way to do it with purely functional code, that is, without relying on side-effects.