开发者

XslCompiledTransform compilation error

开发者 https://www.devze.com 2023-02-27 09:54 出处:网络
I have this xslt stylesheet, in file Empty.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/

I have this xslt stylesheet, in file Empty.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开发者_JS百科="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. But when I try to do the same using code (XslCompiledTransform), I get compilation error exception.

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:

If this is null, external resources are not resolved.

Yet C:\Users\pparik.ESSOX\Desktop\Xslt\General.xslt is an external resource. Try passing in a new XmlUrlResolver() instead of null.

Also, you are over-complicating the load by using XmlTextReader - this is easier:

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消