xml 如何在 XSLT 中使用 fn:replace(string,pattern,replace)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3520622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:15:41  来源:igfitidea点击:

How to use fn:replace(string,pattern,replace) in XSLT

xmlxslt

提问by Thorin Oakenshield

How to use

如何使用

      fn:replace(string,pattern,replace) 

in XSLT

在 XSLT 中

is it like < fn:replace(...)/>??

是不是像< fn:replace(...)/>??

回答by polygenelubricants

The function is specified as follows:

该函数指定如下:

fn:replace($input, $pattern, $replacement, [$flags])

$input        xs:string?  the string to change
$pattern      xs:string   regular expression to match the areas to be replaced
$replacement  xs:string   the replacement string
$flags        xs:string   flags for multiline mode, case insensitivity, etc
return value  xs:string

Note that $patternis a regular expression, and the replacement string also has some special substitution syntax.

注意这$pattern是一个正则表达式,替换字符串也有一些特殊的替换语法。

Here are some examples:

这里有些例子:

# simple replacement
replace('query', 'r', 'as')               queasy

# character class
replace('query', '[ry]', 'l')             quell

# capturing group substitution
replace('abc123', '([a-z])', 'x')       axbxcx123

# practical example
replace('2315551212',                     (231) 555-1212
    '(\d{3})(\d{3})(\d{4})',
    '() -'
)

References

参考

回答by naikus

I think you do it this way:

我认为你这样做:

<xsl:value-of select="fn:replace(value, 'some-pattern', 'with some text')" />

Edit:

编辑:

Found this question on stackoverflow

在stackoverflow上发现了这个问题