调用XslCompiledTransform.Load()时c#:xsl:include

时间:2014-12-03 10:08:53

标签: c# xml xslt

美好的一天,

我有另一个难题。目前,我在项目的资源属性中有2个XSL个文档。其中一个xsl文档包含另一个<xsl:include>

为简单起见,我如何在调用load方法时强制XslCompiledTransform将文档包含在项目的属性中?

    public static string Transform(string xml)
    {
        var xsl = GetXsl();
        var writer = new StringWriter();
        var xpath = new XPathDocument(GetReader(xml));
        var xslTransform = new XslCompiledTransform();
        xslTransform.Load(GetReader(xsl)); // Fails here because it is looking for the included XSL elsewhere.
        xslTransform.Transform(xpath, null, writer);
        return writer.ToString();
    }

    private static XmlReader GetReader(string input)
    {
        var memstream = new MemoryStream();
        var data = Encoding.UTF8.GetBytes(input);
        memstream.Write(data, 0, data.Length);
        memstream.Position = 0;
        return XmlReader.Create(memstream);
    }

    private static string GetXsl()
    {
        return Properties.Resources.AppForms;
    }

例外:

  

无法找到文件'C:\ Users \ myPc \ Documents \ ..... \ bin \ utility.xsl'

正如我所提到的,这两个文件位于项目属性下的资源中。上面代码中加载的是appforms.xsl

0 个答案:

没有答案