function-available() and xsl:fallback
Posted: Sat Sep 26, 2015 11:13 am
I would like to have an XSL that calls out to saxon:evaluate when it can, and falls back to something else when it cannot. I thought that's what function-available() is for, but although I can check availability with that function, I cannot get the XSL to compile with Saxon-PE (doesn't do extensions) when the function itself is in it.
Example fragment:
or even
This feels like catch22. The other option I though of was xsl:fallback, but I could not figure out where to put it as this does not compile either:
Anyone know if my use case is possible, and if so how?
Example fragment:
Code: Select all
<xsl:variable name="hl7date" select="'{format-date(current-date()-xs:yearMonthDuration(''P9Y2M'')-xs:dayTimeDuration(''P30D''),''[Y0001][M01][D01]'')}'"/>
<xsl:if test="function-available('saxon:evaluate')">
<xsl:value-of select="saxon:evaluate(substring($hl7date,2,string-length($hl7date)-2))"/>
</xsl:if>
Code: Select all
<xsl:value-of select="if (function-available('saxon:evaluate')) then saxon:evaluate(substring($hl7date,2,string-length($hl7date)-2)) else ($hl7date)"/>
Code: Select all
<xsl:value-of select="saxon:evaluate(substring($hl7date,2,string-length($hl7date)-2))">
<xsl:fallback><xsl:value-of select="$hl7date"/></xsl:fallback>
</xsl:value-of>