将参数传递给XSLT样式表 [英] Pass parameter to XSLT stylesheet

查看:43
本文介绍了将参数传递给XSLT样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将几个参数传递给XSLT样式表.我遵循以下示例:通过.NET将参数传递到XSLT样式表

I'm trying to pass a couple of parameters to an XSLT style sheet. I have followed the example: Passing parameters to XSLT Stylesheet via .NET.

但是我的转换页面无法正确显示该值.

But my transformed page is not correctly displaying the value.

这是我的C#代码.我必须添加一个自定义函数来执行一些算术运算,因为Visual Studio 2010不使用XSLT 2.0.

Here is my C# code. I had to add a custom function to perform some arithmetic because Visual Studio 2010 doesn't use 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"/>

我想念什么吗?

推荐答案

这是我的XSLT:

Here is my XSLT:

<xsl:template match="/">     
  <xsl:param name="processingId"></xsl:param>     
  ..HTML..     
  <xsl:value-of select="$processingId"/> 

我想念什么吗?

是的,您缺少XSLT转换的调用者可以设置 global-level 参数的值的事实,而不是模板级参数的值.

Yes, you are missing the fact that the invoker of an XSLT transformation can set the values of global-level parameters -- not the values of template-level parameters.

因此,代码必须为:

 <xsl:param name="processingId"/>     

 <xsl:template match="/">     
   ..HTML..     
   <xsl:value-of select="$processingId"/> 
   <!-- Possibly other processing here  -->
 </xsl:template>

这篇关于将参数传递给XSLT样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆