<xsl:variable name="res" select="document('')/*/my:resources/("/>
The value of the select
attribute is not a syntactically correct XPath expression. Every compliant XSLT processor must raise an error.
Solution:
Correct the above to:
<xsl:variable name="vRes" select="document('')/*/my:resources"/>
If there is still an exception raised, do read about the XsltSettings class.
Then create an instance of XsltSettings with this constructor, like this:
XsltSettings(true, false)
Do not enable scripting -- keep the second argument of the constructor as false
.
Below is a more complete code snippet:
// Create the XsltSettings object with document() enabled and script disabled.
XsltSettings settings = new XsltSettings(true,false);
// Create the XslCompiledTransform object and load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("sort.xsl", settings, new XmlUrlResolver());
Update: Another possible reason for an error is when the XSLT stylesheet is dynamically created in memory (doesn't come from file). In this case an XSLT processor typically cannot resolve the relative uri in document('')
.
In this last case the solution is to make the wanted element the content of an xsl:variable
and to use the xxx:node-set()
extension function to address this element.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…