且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将变量发送到xlst?

更新时间:2023-01-01 16:34:15

XSLT处理器应该公开一个API,您可以在运行转换之前设置全局样式表参数。在.NET框架中,您需要创建一个 System.Xml.Xsl的实例。 XsltArgumentList ,调用AddParam方法来设置您在XSLT样式表中使用***xsl:param元素定义的任何参数,然后将该XsltArgumentList实例传递给用于运行XslCompiledTransform实例的Transform方法。转换。
因此在样式表中你可以使用例如

An XSLT processor is supposed to expose an API where you can set global stylesheet parameters before you run the transformation. In the .NET framework you need to create an instance of System.Xml.Xsl.XsltArgumentList , call the AddParam method to set any parameters you have defined in the XSLT stylesheet with top-level xsl:param elements, and then pass in that XsltArgumentList instance to the Transform method of an XslCompiledTransform instance you use to run the transformation.
So in the stylesheet you would use e.g.
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:param name="foo"/>

  <xsl:template match="/">
    <xsl:for-each select="root/bar[baz =


foo]">
...
< / xsl:for-each>
< / xsl:template>

< / xsl:stylesheet>
foo]"> ... </xsl:for-each> </xsl:template> </xsl:stylesheet>


定义名为foo的全局参数,然后可以将其用作

to define a global parameter named foo that you can then use as


你的XPath表达式中的foo。然后,您的.NET代码将使用XsltArgumentList并调用AddParam("foo",""",Response.QueryString("whatever"))来传递查询字符串中收到的值。
foo in your XPath expressions. Your .NET code would then use an XsltArgumentList and call AddParam("foo", "", Response.QueryString("whatever")) to pass in a value received in the query string.