Michael,

 

It works !

 

Thank you very much !  J

 

 

But, I had to write this :

 

 <xsl:value-of select="jav:add($countField, '1')"/>

 

Instead of  <xsl:value-of name="countField1" select="jav:add($countField, '1')"/>

 

Regards

 

Laurent

 

 

De : Michael Kay [mailto:mike@saxonica.com]
Envoyé : lundi 30 septembre 2013 14:29
À : Mailing list for the SAXON XSLT and XQuery processor
Objet : Re: [saxon] Pb with using java mthod with Saxon

 

 

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')"/>

<Fields>

                             <xsl:variable name="Fields">

                                  

 

                                   <Field>

                                         <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>

                                   </Field>

                                                          

                             </xsl:variable>

                                  

                             <xsl:copy-of select="$Fields"/>

                        </Fields>

 

However, there is probably a better way to do it with purely functional code, that is, without relying on side-effects.

 

Michael Kay

Saxonica