Hi Michael, 

Thanks a lot for your response. 

I  tried to run in 1.0 compatibility mode (version="1.0" on the xsl:function) and it works.

I tried your solution with "use-when" and it works also fine, I prefer this more elegant way, sticking in 2.0.

I actually didn't know the "use-when" attribute, seems usefull  ! It seems to prevent compilation errors whereas choose/when test or (if test) don't in 2.0.

The only problem is that the <xsl:message> is displayed each time the function is called (a lot !). So I removed the error message from within the function and made a special function to display unavailable function message :

<xsl:function name="igs:functions.available.test">
<xsl:message use-when="not(function-available('java-uri:new'))" >[WARNING] : java function is not available</xsl:message>
</xsl:function>

and a call it once from the <xsl:template match="/"> of my main xsl.

All those function are actually stored in a common xsl which only contains generic named templates and functions, I think I can't display igs:functions.available.test from within THIS "library xslt". (if I call igs:functions.available.test from a global variable in common.xsl, it will not be evaluated as long as the variable isn't used, and I can't call it once cause I have no <xsl:template match="..."> in this XSLT).
I think there is no way to generaly enforce an <xsl:message> to be displayed only once, except using terminate="yes" but I actually don't want to stop the transformation.

Well it becomes maybe out of topic ;-) and I'm fine with the one call in main.xsl.

Thanks for the tip about <xsl:value> and boolean, i'll change it to sequence everytime now !

All is sequence in xpath 2, I should remember that :) ! 

Best regards, 
Matthieu

2012/11/1 Michael Kay <mike@saxonica.com>
In XPath 2.0 a function call to an unknown function is a static error whether or not the function is actually called.

One workaround is to run in 1.0 compatibility mode (set version="1.0" perhaps on the xsl:function element): in 1.0, calling a function that doesn't exist was a dynamic error. Another solution, rather better, is to use use-when:


<xsl:function name="igs:file-exists" as="xs:boolean">
  <xsl:param name="uri" as="xs:string"/>   
  <xsl:sequence
       use-when="function-available('java-uri:new')"
       select="java-file:exists(java-file:new(java-uri:new($uri)))"/>
  <xsl:sequence use-when="not(function-available('java-uri:new'))" select="true()"/>
  <xsl:message  use-when="not(function-available('java-uri:new'))" >[ERROR] : java function is not available</xsl:message></xsl:function>

(Note: xsl:value-of constructs a text node. You don't want to do that in a function that's supposed to return a boolean.)

Michael Kay
Saxonica

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--
Matthieu Ricaud-Dussarget
IGS-CP - Développeur XML
05 45 37 08 90