As Martin wrote, Microsoft's processor only supports 1.0 - even now, in 2016. I had a similar problem (I needed to do work with regular expressions within my XSLT) and I resolved it by using inline C# to do the work.
I based my solution on this example: XSLT Stylesheet Scripting Using <msxsl:script> (MSDN)
You'll have to add a few things to your xsl:stylesheet
node. Mine looks like:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
exclude-result-prefixes="msxsl">
Then, you'll define your script. Mine was something like:
<!-- Script to check for URLs in values -->
<msxsl:script language="C#" implements-prefix="user">
<![CDATA[
public string ExtractUrl(string str)
{
return Regex.Match(str, @"(https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{2,256}.[a-z]{2,6}([-a-zA-Z0-9@:%_+.~#?&//=]*))").Value;
}
]]>
</msxsl:script>
I was then able to invoke the function within my XSLT:
<xsl:variable name="extractedUrl" select="user:ExtractUrl(.)"></xsl:variable>
It's not mentioned on the tutorial page, but where I processed the XSLT on the server, I also had to create an XsltSettings
object to enable script execution:
XsltSettings settings = new XsltSettings(false, true); // enable script execution
XsltCompiledTransform transform = new XslCompiledTransform();
transform.Load("template.xsl", settings, new XmlUrlResolver());
Of course, consider security - make sure your XSLT file contains only trusted and/or sanitized input if you're allowing the execution of arbitrary C# scripts.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…