Function “fn:encode-for-uri” causes XSLT to error

2019-06-24 01:02发布

问题:

I need to URL Encode a string in XSLT but the function:

fn:encode-for-uri

breaks the script. I checked it out online and apparently it's part of the namespace

http://www.w3.org/2005/xpath-functions

So i added the following line to the top of my XSLT file to no avail.

xmlns:fn="http://www.w3.org/2005/xpath-functions" 

Any ideas? I stepped through it in Visual Studio and I got the exception:

Cannot find a script or an extension object associated with namespace 'http://www.w3.org/2005/xpath-functions'.

Any ideas?

-Ev

回答1:

Visual Studio uses a .NET XSLT processor -- that is XSLT 1.0 processor.

The function encode-for-uri() is a standard function only in XPath 2.0 / XQuery . XSLT 1.0 processors only use XPath 1.0 and the encode-for-uri() function is not implemented and availavle.

In order to use this function you need an XSLT 2.0 processor, such as Saxon.NET or XQSharp.



回答2:

 <xsl:value-of select="encode-for-uri(...)"/>


标签: xml xslt