如何检查 xquery 中的字符串是否包含双引号?
我是 xQuery 的新手,尝试在 oracle osb 中编写 xquery 片段,并想检查我的查询项是否由双引号引起来。我有如下代码,但 fn:replace 或 fn:contains 不起作用。 我输入的字符串,qt =“test”,那么它是一个短语如果qt = test,那么它很简单
我怎样才能做到这一点?
if ($qt != "")
then let $newQt := fn:replace($qt,'"','\\"')
return
(
if (fn:contains($newQt,'\\"'))
then <stan:query>
<stan:queryTerm>{
fn:concat('string("',
$newQt,
'", mode="phrase", annotation_class="user")'
)
}</stan:queryTerm>
<stan:mode>{'RAW'}</stan:mode>
</stan:query>
else <stan:query>
<stan:queryTerm>{
fn:concat(
'string("',
$newQt,
'", mode="simpleany", annotation_class="user")'
)
}</stan:queryTerm>
<stan:mode>{'RAW'}</stan:mode>
</stan:query>
)
else <stan:query>
<stan:queryTerm>{$newQt}</stan:queryTerm>
<stan:mode>{'AND'}</stan:mode>
</stan:query>
I am new to xQuery , trying to write xquery snippets in oracle osb and want to check if my query term is bounded by double quote. I have the code like below, but fn:replace or fn:contains is not working.
My input string , qt = "test", then it is a phrase if qt = test, then it is simple
How can I make this work ?
if ($qt != "")
then let $newQt := fn:replace($qt,'"','\\"')
return
(
if (fn:contains($newQt,'\\"'))
then <stan:query>
<stan:queryTerm>{
fn:concat('string("',
$newQt,
'", mode="phrase", annotation_class="user")'
)
}</stan:queryTerm>
<stan:mode>{'RAW'}</stan:mode>
</stan:query>
else <stan:query>
<stan:queryTerm>{
fn:concat(
'string("',
$newQt,
'", mode="simpleany", annotation_class="user")'
)
}</stan:queryTerm>
<stan:mode>{'RAW'}</stan:mode>
</stan:query>
)
else <stan:query>
<stan:queryTerm>{$newQt}</stan:queryTerm>
<stan:mode>{'AND'}</stan:mode>
</stan:query>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题很难回答,因为我无法重复您的问题(我根本无法轻松地让您的代码运行)。我也没有使用过“oracle osb”,所以我不确定这是否会有很大帮助。
我能够使用以下 xquery 完成我认为您正在尝试执行的操作。 (我的处理器是 Saxon-HE XQuery 9.3.0.4。我不必在函数上使用
fn:
前缀,但也许您在 Oracle 中这样做?)XQuery :
输出:
输出 (将
$qt
更改为let $qt := 'TEST'
后):output (将
$qt
更改为let $qt := ''
后,这就是您的if ($qt != "") 然后)
会很吸引):希望这会有所帮助。
This question is hard to answer because I can't duplicate your issue (I can't easily get your code to run at all). I also haven't used "oracle osb" so I'm not sure if this is going to be much help at all.
I was able to accomplish what I think you're trying to do using the following xquery. (My processor is Saxon-HE XQuery 9.3.0.4. I don't have to use the
fn:
prefixes on the functions, but maybe you do in oracle?)XQuery:
output:
output (after changing
$qt
tolet $qt := 'TEST'
):output (after changing
$qt
tolet $qt := ''
which is what yourif ($qt != "") then)
would be catching):Hope this helps somehow.
要检查字符串是否包含双引号,请使用
fn:contains
:您的代码区分三种情况,即
我会这样写:
一些额外的注释:
To check whether a string contains a double quote, use
fn:contains
:Your code distinguishes three cases, namely
I would write it like this:
Some extra remarks: