XPath 表达式 - 替换空格

XPath Expression - Replace white spaces

我想用 XPath 表达式中的 %20 替换字符串之间的所有空格。请让我知道该怎么做。我尝试使用 normalize-space 但这只会删除前导和尾随的空格。请帮忙

I want to replace all white spaces that comes in between a string by %20 in an XPath expression.

XPath 2.0

使用replace($s, $pattern, $replacement):

replace(/path/to/it, '\s', '%20')

或者,正如 Michael Kay 所指出的那样,考虑 encode-for-uri($uri-part), which performs this substitution among other URI escaping rules (RFC 3986, section 2)

XPath 1.0

您需要 XSLT、Java、C#、Python 等托管语言的帮助


I tried using normalize-space but this removes only leading and trailing white spaces.

校正normalize-space() 删除前导和尾随白色space, 合并白色的每个内部序列space 个字符到单个 space 个字符。