Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# xsl:import时XslCompiledTransform失败_C#_.net_Uri_Xslt_Xslcompiledtransform - Fatal编程技术网

C# xsl:import时XslCompiledTransform失败

C# xsl:import时XslCompiledTransform失败,c#,.net,uri,xslt,xslcompiledtransform,C#,.net,Uri,Xslt,Xslcompiledtransform,我几乎没有XSLT文件,索引样式表使用xsl:import导入布局。VS表示XSLT有效,但Load操作引发XSLT编译异常,表示无法导入我的布局文件。它尝试在c:\windows\system32而不是我的项目目录中找到它 Index.xsl: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

我几乎没有XSLT文件,索引样式表使用xsl:import导入布局。VS表示XSLT有效,但Load操作引发XSLT编译异常,表示无法导入我的布局文件。它尝试在c:\windows\system32而不是我的项目目录中找到它

Index.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:h ="urn:helper"
    exclude-result-prefixes="msxsl"
>
    <xsl:import href="..\Shared\Layout.xsl"/>

    <xsl:template match="/content" mode="content">
        <p>Hello world</p>
    </xsl:template>

</xsl:stylesheet>

那是ASP.NET吗?然后使用

  xsl.Load(MapPath(viewPath), null, new XmlUrlResolver());

反斜杠不是URI中的有效路径分隔符。试试正斜杠。我怀疑这会有什么不同-微软软件倾向于原谅这个错误-但它会消除一个可能的原因,并使您的代码更具可移植性。
string viewPath = "~/Views/Home/Index.xsl";
var stylesheet = HostingEnvironment.VirtualPathProvider.GetFile(viewPath);
var xsl = new XslCompiledTransform();
using (var stream = stylesheet.Open())
using (var tmpl = XmlReader.Create(stream))
{
    xsl.Load(tmpl, null, new XmlUrlResolver());
}
  xsl.Load(MapPath(viewPath), null, new XmlUrlResolver());