[英]XslCompiledTransform fails on xsl:import
I have few XSLT files, index stylesheet imports layout using xsl:import. 我的XSLT文件很少,索引样式表使用xsl:import导入布局。 VS says that XSLT is valid, but Load operation raises xslt compilation exception, it says cannot import my layout file.
VS说XSLT有效,但是Load操作引发xslt编译异常,它说不能导入我的布局文件。 It tries ti find it in c:\\windows\\system32 instead of my project dir.
它会尝试在c:\\ windows \\ system32而不是我的项目目录中找到它。
Index.xsl: 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>
and Layout.xsl: 和Layout.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" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" encoding="utf-8" indent="yes" />
<xsl:template match="/xml">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<xsl:apply-templates select="/xml" mode="content" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Next I'm trying to apply transformation on my XML: 接下来,我尝试在XML上应用转换:
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());
}
Is that ASP.NET? 那是ASP.NET吗? Then use
然后使用
xsl.Load(MapPath(viewPath), null, new XmlUrlResolver());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.