我想将几个参数传递给XSLT样式表。我遵循了这个例子:Passing parameters to XSLT Stylesheet via .NET。将参数传递给XSLT样式表
但我的转换后的页面没有正确显示值。
这是我的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相同的级别:模板元素 –
Pawel
我不确定您在顶层的含义。当我在我的问题中粘贴时,参数定义低于。上面是标签。 –
coson
我的意思是它不应该在xsl:template中。尝试这样: ' ...' –
Pawel