![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Problem calling functions from within XSLT? [Thread Next] Re: Problem calling functions from within XSLT?To: NULL Date: 1/12/2008 3:36:00 PM Craig Sanders wrote: > I hope someone can help. I can't for the life of me, seem to work out how to > call functions from within XSLT code. I have a simple XSLT file (called > function.xsl) which contains the following code ; > > <?xml version="1.0" encoding="ISO-8859-1"?> > <xsl:stylesheet > version="2.0" This is an XSLT 2.0 stylesheet. The XSLT processors provided by Microsoft (MSXML (3, 4, 5 , 6), XslTransform, XslCompiledTransform) do only support XSLT 1.0 but not 2.0. > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> The standardized namespace is http://www.w3.org/2005/xpath-functions. > <xsl:output > method='html' > version='1.0' > encoding='UTF-8' > indent='yes'/> > > > <xsl:template match="/"> > <html> > <body> > <xsl:if > test="fn:base-uri()" base-uri is an XPath 2.0 function not defined in XSLT/XPath 1.0 so you will need an XSLT 2.0 processor to successfully exectute this stylesheet. > xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> See above, the namespace is http://www.w3.org/2005/xpath-functions. > XSLT function call succeeded. > My corresponding XML file (which is called function.xml) resides in the same > directory as the XSLT file and its contents are as follows ; > > <?xml version="1.0" encoding="ISO-8859-1"?> > <?xml-stylesheet type="text/xsl" href="function.xsl"?> > <body> > </body> > > When I attempt to load up this XML file into IE6 I get the following error ; > > The XML page cannot be displayed > Cannot view XML input using XSL style sheet. Please correct the error and > then click the Refresh button, or try again later. > > Namespace 'http://www.w3.org/2005/02/xpath-functions' does not contain any > functions. > > When I load the XML file into the latest versions of Opera and Firefox, the > diagnostic messages are even less helpful! They simply state that there was > a problem processing the XSLT. As said, you need an XSLT 2.0 processor to run that stylesheet. And XSLT 2.0 is only one year old so far and XSLT processors in browsers (including IE, Opera, Mozilla/Firefox) do not support XSLT 2.0, only 1.0. > So then I installed Saxon version 9.0 Base. When I process the two files > using Saxon I get the following error message ; > > Error at xsl:if on line 21 of > file:/D:/Documents%20and%20Settings/Craig%20Sanders/My%20Documents/xslt/function.xsl: > XPST0017: XPath syntax error at char 13 on line 21 in {fn:base-uri()}: > Cannot find a matching 0-argument function named > {http://www.w3.org/2005/02/xpath-functions}base-uri() > Failed to compile stylesheet. 1 error detected. You have the wrong namespace, use http://www.w3.org/2005/xpath-functions (respectively, as that is the default function namespace, you can omit it and simply call base-uri()): <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="/"> <xsl:value-of select="base-uri()"/> </xsl:template> </xsl:stylesheet> That works fine for me with Saxon 9 B. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
