如何删除新行字符.
Sample Code.
let $b := <root><title>Fees • Levies<?brk type="line"?>
Other file</title></root>
return replace($b//title/text(),'\n','')
Expected Output :
Fees • Levies Other file
Run Code Online (Sandbox Code Playgroud)
我能想到的一些选择:
fn:replace() - 但你必须考虑两个可能的字符
let $b := <root><title>Fees • Levies<?brk type="line"?>
Other file</title></root>
return fn:replace(fn:data($b//title), '(\r?\n|\r)', '')
Run Code Online (Sandbox Code Playgroud)
但这可能会给你留下额外的空白,具体取决于它是如何创建和格式化的.因此,您可能还希望使用fn:normalize-space()立即清理空格和换行符.
let $b := <root><title>Fees • Levies<?brk type="line"?>
Other file</title></root>
return fn:normalize-space(fn:data($b//title))
Run Code Online (Sandbox Code Playgroud)
您可能还注意到我使用了fn:data().这是出于习惯.然而,有一个伟大的博客帖子在这里的文字,字符串,数据的主题.