如何将参数传递给可在 xsl:key 中使用的 xslt? [英] How can you pass in a parameter to an xslt that can be used in a xsl:key?

查看:22
本文介绍了如何将参数传递给可在 xsl:key 中使用的 xslt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个 XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="paramvalue" />
  <xsl:key name="test" match="$paramvalue" use="generate-id()" />

  <!-- template rules -->
</xsl:stylesheet>

失败,因为您似乎在 xsl:keymatch 属性中没有参数值.除了动态修改 xslt 之外,还有什么办法可以做到这一点吗?

Fails because you can't seem to have a parameter value in the match attribute of an xsl:key. Is there any way to do this other than modifying the xslt on the fly?

推荐答案

如何将参数传递给可以在 xsl:key 中使用的 xslt?

How can you pass in a parameter to an xslt that can be used in a xsl:key?

为此使用 XSLT 2.0.

Use XSLT 2.0 for this.

在 XSLT 1.0 中,use 属性或 match 属性的值包含 VariableReference 是错误的."根据规范

In XSLT 1.0 "It is an error for the value of either the use attribute or the match attribute to contain a VariableReference." as per spec

这个限制被放在规范中,目的是防止循环引用链.

This limitation was put in the spec with the goal of preventing a chain of circular references.

除了动态修改 xslt?

Is there any way to do this other than modifying the xslt on the fly?

是的,您的 XSLT 代码可能会生成一个新的 xslt 样式表,它使用键定义中参数的特定.

Yes, your XSLT code may generate a new xslt stylesheet that uses the specific value of the parameter in the definition of the key.

或者,如果参数的值来自有限集合,您可以为每个可能的值定义键——并且参数本身将包含要使用的键的名称-- 请注意,key() 函数的键名参数可以是任何表达式,包括变量引用.

Or, in case the values of the parameter are from a finite set, you may have keys defined for every possible value -- and the parameter itself will contain the name of the key to use -- do note that the key-name argument of the key() function can be any expression, including variable references.

这篇关于如何将参数传递给可在 xsl:key 中使用的 xslt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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