function-available() and xsl:fallback
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 3
- Joined: Thu Sep 10, 2015 6:24 pm
function-available() and xsl:fallback
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>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: function-available() and xsl:fallback
Hi,
I found an explanation and the solution for Saxon-HE here:
[saxon] Saxon-HE and function-available
The problem seems to be that references to functions are resolved statically at compile time and Saxon-HE does not resolve Saxon extension functions.
A simple solution is to use use-when="function-available()":
Regards,
Adrian
I'm guessing you're referring to Saxon-HE since that is the one that doesn't support extensions. Saxon-PE should work just fine.ahenket wrote: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.
I found an explanation and the solution for Saxon-HE here:
[saxon] Saxon-HE and function-available
The problem seems to be that references to functions are resolved statically at compile time and Saxon-HE does not resolve Saxon extension functions.
A simple solution is to use use-when="function-available()":
Code: Select all
<xsl:value-of select="saxon:evaluate(substring($hl7date,2,string-length($hl7date)-2))" use-when="function-available('saxon:evaluate')"/>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service