RE: [xsl] Forcing a call to a Java method

Subject: RE: [xsl] Forcing a call to a Java method
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 24 Jun 2006 08:28:59 +0100
> I have a Java method I want to call from my XSLT script (I am 
> using Saxon of course).  I use the following code: 
>  
>    <xsl:variable name="ignore" select="foo:bar()"/>
> 
> The bar method doesn't return anything of value, it really is 
> a void method that I have returning the dummy value 1.  But 
> the xsl:variable method is optimized out since I never use 
> the returned value. 
>  
> What is the syntax to force the XSLT engine to call foo:bar? 

Firstly, extension functions are product-dependent so it would be more
appropriate to ask this on the Saxon list.

In Saxon, I suggest you do

  <xsl:sequence select="foo:bar()"/>

If the method is void, then the xsl:sequence returns an empty sequence, but
Saxon (deliberately) doesn't look at the external method signature to
determine in advance that it's void, so the function will actually be
called.

This approach also makes it much more likely that methods will be called in
the expected order.

Michael Kay
http://www.saxonica.com/

Current Thread