0

XSLTファイルがほとんどないので、インデックススタイルシートはxsl:importを使用してレイアウトをインポートします。VSはXSLTが有効であると言っていますが、ロード操作で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>

および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>

次に、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());
}
4

1 に答える 1

1

それはASP.NETですか?次に使用します

  xsl.Load(MapPath(viewPath), null, new XmlUrlResolver());
于 2011-04-25T09:55:33.560 に答える