简体   繁体   English

XslCompiledTransform编译错误

[英]XslCompiledTransform compilation error

I have this xslt stylesheet, in file Empty.xslt: 我在文件Empty.xslt中有此xslt样式表:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:nrki="http://www.essox.cz/xslt/nrki" xmlns:date="http://www.essox.cz/xslt/date" version="1.0" exclude-result-prefixes="msxsl" extension-element-prefixes="nrki date"> <xsl:import href="C:\\Users\\pparik.ESSOX\\Desktop\\Xslt\\General.xslt" /> <xsl:import href="C:\\Users\\pparik.ESSOX\\Desktop\\Xslt\\Nrki\\General.xslt" /> <xsl:output method="text" indent="yes" /> <xsl:template match="@* | node()"> <xsl:if test="nrki:IsInLastDays('15042011', 6)"> je </xsl:if> </xsl:template> </xsl:stylesheet>

When I select menu item (in Visual studio) XML / Show XSLT Output, I get correct results. 当我选择菜单项(在Visual Studio中)为XML / Show XSLT Output时,我得到正确的结果。 But when I try to do the same using code (XslCompiledTransform), I get compilation error exception. 但是,当我尝试使用代码(XslCompiledTransform)执行相同操作时,出现编译错误异常。

string output = string.Empty;
XslCompiledTransform transform = new XslCompiledTransform(true);
XsltSettings sett = new XsltSettings(true, true);
transform.Load(new XmlTextReader(@"C:\Users\pparik.ESSOX\Documents\Essox\Zdrojové kódy\SES\Visual studio\SesSolution\TestXslt\Xslt sablony\Empty.xslt"), sett, null);
StringWriter sr = new StringWriter();
transform.Transform(this.EvaluationInput.CreateNavigator(), null, sr);
output = sr.ToString();

Any idea why? 知道为什么吗? Thanks a lot, Petr 非常感谢,彼得

See the comment on the XmlResolver argument where you are passing in null : 请参见XmlResolver参数的注释,在其中传递null

If this is null, external resources are not resolved. 如果为空,则不解析外部资源。

Yet C:\\Users\\pparik.ESSOX\\Desktop\\Xslt\\General.xslt is an external resource. 但是C:\\Users\\pparik.ESSOX\\Desktop\\Xslt\\General.xslt 外部资源。 Try passing in a new XmlUrlResolver() instead of null . 尝试传入一个new XmlUrlResolver()而不是null

Also, you are over-complicating the load by using XmlTextReader - this is easier: 另外,使用XmlTextReader会使负载过于复杂-这更容易:

transform.Load(path, sett, new XmlUrlResolver());

For info, you can supply your own custom resolvers if you like - for example, I wrote one that re-mapped relative paths to contents from a resx, so the files could be edited normally in the IDE but then included as embedded resources (but still resolve their siblings correctly). 有关信息,您可以根据需要提供自己的自定义解析程序-例如,我编写了一个自定义解析程序,该映射程序重新映射了来自resx的内容的相对路径,因此可以在IDE中正常编辑文件,然后将其作为嵌入式资源包含(但仍能正确解决其兄弟姐妹的问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM