In order to use xpath-functions (specifically the fn part), I included the respective namespace into my xslt stylesheet, like so:
<xsl:stylesheet
version="2.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
>
As specified by W3C.
However, when I use fn:document-uri, my XSLT engines tell me I called an unknown function/extension:
<xsl:variable name="uri" select="fn:document-uri()" />
Opera says:
This document had an invalid XSLT stylesheet. Error message from the XSLT engine:
Error: XPath expression compilation failed: fn:document-uri()
Details: compilation error (characters 1-17, “fn:document-uri()”): unknown function called: ‘{ http://www.w3.org/2005/xpath-functions, document-uri }’
Firefox says:
Error during XSLT transformation: An unknown XPath extension function was called.
And xsltproc refuses transformation, because of xslt 2.0.
So, how do I specify the fn namespace properly?
The problem is that you are using an XSLT 1.0 processor and an XSLT 1.0 processor doesn’t know (and must not know) anything about XPath 2.0 functions.
If you use a real XSLT 2.0 processor, you don’t even have to specify the function namespace — it is a default namespace for any unprefixed function name.
For example, this XSLT 2.0 transformation:
when executed with Saxon 9.1.5 under the XSelerator, produces correctly the URLs of the source XML document and the stylesheet itself: