[英]XSL functions with xsl param as parameters
I will try to keep the terminology clear here, the overloading of terms is making this complicated. 在这里,我将尝试使术语保持清晰,术语的重载使这一过程变得复杂。
I have a transform that I am passing an attribute to fill a xsl:param, this is working 我有一个转换,我传递了一个属性来填充xsl:param,这是可行的
<xsl:param name="platform"/>
This will print out if I use 如果我使用这将打印出来
<xsl:value-of select='$platform'/>
Instead of printing this attribute/param I need to pass it to a function. 而不是打印此属性/参数,我需要将其传递给函数。 I have tried 我努力了
<xsl:value-of select="replace(current(),'replaceMe','$platform')"/>
I receive the error 我收到错误
Invalid replacement string in replace(): $ sign must be followed by digit 0-9 replace()中无效的替换字符串:$符号后必须跟数字0-9
Is there a way I can pass the param into the function? 有没有办法可以将参数传递给函数?
If so, how do I need to format it? 如果是这样,我该如何格式化?
You mean 你的意思是
<xsl:value-of select="replace(current(), 'replaceMe', $platform)" />
$platform
is a variable. $platform
是一个变量。
"$platform"
is an invalid replacement string in the context of the replace()
function, which works with regex and expects back-refereces like $1
or $2
in the replacement string when it sees $
. 在replace()
函数的上下文中, "$platform"
是无效的替换字符串,该函数与regex一起使用,并且在看到$
时期望替换字符串中的反向引用像$1
或$2
。
Logical conclusion: You will see the same error again as soon as the $platform
variable accidentally contains a $
, and another error when 'replaceMe'
accidentally is an invalid regular expression. 逻辑结论:一旦$platform
变量意外包含$
,您将再次看到相同的错误,而当'replaceMe'
偶然是无效的正则表达式时,您将再次看到另一个错误。 If it happens to be a valid regular expression and you don't know it, you might see other unexpected behavior. 如果它恰好是有效的正则表达式,并且您不知道,则可能会看到其他意外行为。
Therefore - if you want to do verbatim search-and-replace with variables - you must properly regex-escape all special characters in the search pattern and at least escape any $
and \\
in the replacement string. 因此,如果要对变量进行逐字搜索和替换,则必须正确地对搜索模式中的所有特殊字符进行正则表达式转义,并至少在替换字符串中转义任何$
和\\
。 A robust "verbatim" replace call looks like this: 一个健壮的“ verbatim”替换调用如下所示:
replace(
$subject,
replace($searchString, '[.\[\]\\|^$?*+{}()-]','\\$0'),
replace($replacement, '[\\$]', '\\$0')
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.