XQuery 将土耳其语字符的“ü”替换为“u”

问题描述

我有动态参数的功能。我为此使用了 MicroStrategy 工具。

let $uri := replace('http://url/suggest?searchTerm=DYNAMIC PROMPT','\s+','%20')

我想在这函数中将 'ü' 替换为 'u'。我已经使用 ('\s+','%20') 作为空格字符。

解决方法

多个replace函数可以嵌套:

let $string := 'http://url/suggest?searchTerm=DüNAMIC PROMPT'
let $uri := replace(replace($string,'\s+','%20'),'ü','u')
return $uri

为了替换单个字符,您还可以使用 translate 函数:

let $string := 'http://url/suggest?searchTerm=DüNAMIC PROMPT'
let $uri := translate($string,' üÜöÖäÄ','+uUoOaA')
return $uri
,

我可以对多个字符使用“let $uri := replace(replace($string,'u')”吗? 例如: let $uri := replace(replace($string,'üöÖäÄ','+uUoOaA')

因为我需要两个替换盒。

Microstrategy 不支持这种情况。例如,我给出了“Müşteri”关键字,它给了我不同的答案:(

,

我同意 Leo 的建议,即 fn:encode-for-uri() 是适用于所述用例的方法 - 即在构造 URL 时处理空格、特殊字符和变音符号。

但如果您有兴趣从字符串中去除变音符号,您可以这样做:

xquery version "3.1";

"Müşteri" 
=> normalize-unicode("NFD") 
=> replace("\p{IsCombiningDiacriticalMarks}","")

这将返回 Musteri

作为参考,这是基于我在 https://gist.github.com/joewiz/af04074c28e0ae2a1b92 上发布的 Gist。