【发布时间】:2012-10-08 19:04:43
【问题描述】:
我正在尝试将几个参数传递给 XSLT 样式表。我已经按照示例:Passing parameters to XSLT Stylesheet via .NET。
但是我转换后的页面没有正确显示值。
这是我的 C# 代码。我不得不添加一个自定义函数来执行一些算术,因为 Visual Studio 2010 不使用 XSLT 2.0。
var args = new XsltArgumentList();
args.AddExtensionObject("urn:XslFunctionExtensions", new XslFunctionExtensions());
args.AddParam("processingId", string.Empty, processingId);
var myXPathDoc = new XPathDocument(claimDataStream);
var xslCompiledTransformation = new XslCompiledTransform(true);
// XSLT File
xslCompiledTransformation.Load(xmlReader);
// HTML File
using (var xmlTextWriter = new XmlTextWriter(outputFile, null))
{
xslCompiledTransformation.Transform(myXPathDoc, args, xmlTextWriter);
}
这是我的 XSLT:
<xsl:template match="/">
<xsl:param name="processingId"></xsl:param>
..HTML..
<xsl:value-of select="$processingId"/>
我错过了什么吗?
【问题讨论】:
-
您在顶层有
<xsl:param name="processingId">吗?似乎您在将创建本地参数的模板中定义了参数。对于外部参数,参数必须是全局的,因此必须与 xsl:template elements 在同一级别定义 -
我不确定你在顶层是什么意思。我在问题中粘贴的参数定义位于 下方。上面是
标签。 -
我的意思是它不应该在 xsl:template 中。试试这样的:
<xsl:stylesheet ...> <xsl:param name="processingId" /><xsl:template match="/"><xsl:value-of select="$processingId"/>...
标签: c# xslt transformation