Project

Profile

Help

use-when="function-available('json-to-xml')" always true?

Added by T Hata over 7 years ago

Hi,

With these two similar stylesheets on 9.7.0.14 HE,



	
	
		
			
		
	



	
	
		
			
		
	

The first one runs successfully (by ignoring xsl:value-of). The second one results in @XPST0017: System function json-to-xml#1 is not available with this host-language/version/license@.

I'm wondering why they behave differently.


Replies (2)

RE: use-when="function-available('json-to-xml')" always true? - Added by Michael Kay over 7 years ago

This is a messy area, largely because both the W3C specifications and the Saxon implementation are in a transitional phase. We implement different versions/levels of the function library for free-standing XPath expressions versus XSLT stylesheets, and for Saxon-HE versus Saxon-PE/EE.

Although the spec for function-available() specifically mentions use-cases involving [xsl:]use-when, a call on function-available(F) is testing whether F is available for use within the use-when expression, it's not testing whether it's available for use in the ordinary XPath expressions contained in XSLT instructions subject to the use-when. So function-available('fn:key') called within a use-when expression is supposed to return false, because fn:key can't be used in a use-when expression. This is probably why the spec suggests that it's primarily intended for testing the availability of extension functions.

Internally each function is labelled with a set of flags indicating which environments it is applicable to (i.e. which environments it is available in). The flags for json-doc say "XPATH31" while the flags for json-to-xml say XPATH31 | XSLT30 | USE_WHEN. The difference correctly reflects the fact that json-doc is defined in XPath 3.1, while json-to-xml is defined in both XPath 3.1 and XSLT 3.0.

The implementation of function-available() tests whether there is a non-empty intersection between this set of flags and the current execution environment, Within xsl:use-when, the current execution environment is USE_WHEN, so for json-to-xml() the test passes (and indeed, I suspect, a call on the json-to-xml() function within the use-when expression would probably succeed). But within the ordinary XPath expressions in the select attribute of an XSLT 2.0 stylesheet, none of the flags XPATH31 | XSLT30 | USE_WHEN is set so the function call fails.

This clearly isn't very desirable behaviour but I think that any attempt to fix it within the current design would probably have adverse consequences. We have implemented a much more flexible scheme for configuration system function libraries for the 9.8 release which will hopefully make this go away. Eventually, once the current round of specs all reach Recommendation status, we may decide to drop the attempt to conform to XSLT 2.0 as well as XSLT 3.0 (that is, we may abandon the attempt to prevent XSLT 2.0 stylesheets using XSLT 3.0 features) which would certainly simplify things a lot.

RE: use-when="function-available('json-to-xml')" always true? - Added by T Hata over 7 years ago

Thanks for the clarification. I'll pay attention to the actual behavior before making dependency on function-available() in @use-when.

    (1-2/2)

    Please register to reply