问题描述
我想在我的XSLT文件中使用嵌入的资源,但在调用的文件(......)C#抱怨说,加载文件时出错。
我想在XSLT文件中使用定义的资源并以此让他们:文件('')/的 /我:资源/ 的...
我怎样才能做到这一点?
前的xsl:
<?XML版本=1.0编码=UTF-8>?;
<的xsl:样式版本=1.0的xmlns:XSL =http://www.w3.org/1999/XSL/Transform
的xmlns:我=XSLT的gruper-V1。 2.xsl排除,结果为前缀=我>
<我:资源>
<一种> tryb< /单>
< /我:资源>
< XSL:变量名=RES选择=文件('')/ * /我:资源/(/>
< / XSL:样式>
我怎样才能获得这种结构,而不在C#中的异常?我会期间静态添加通过变换。前戏,一切工作正常。
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.
这篇关于使用文件()在.NET XSLT的功能产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!