Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如果字符串中有双引号,如何签入xquery?_String_Xquery - Fatal编程技术网

String 如果字符串中有双引号,如何签入xquery?

String 如果字符串中有双引号,如何签入xquery?,string,xquery,String,Xquery,我是xQuery新手,尝试在OracleOSB中编写xQuery片段,并想检查我的查询词是否以双引号为界。我有如下代码,但fn:replace或fn:contains不起作用。 我的输入字符串qt=“test”,那么它就是一个短语,如果qt=test,那么它很简单 我怎样才能做到这一点? if($qt!=“”) 然后让$newQt:=fn:replace($qt,“,“\\”) 返回 ( if(fn:contains($newQt,“\\”)) 然后 { fn:concat('strin

我是xQuery新手,尝试在OracleOSB中编写xQuery片段,并想检查我的查询词是否以双引号为界。我有如下代码,但fn:replace或fn:contains不起作用。 我的输入字符串qt=“test”,那么它就是一个短语,如果qt=test,那么它很简单

我怎样才能做到这一点?
if($qt!=“”)
然后让$newQt:=fn:replace($qt,“,“\\”)
返回
(    
if(fn:contains($newQt,“\\”))
然后
{
fn:concat('string(“'),
$newQt,
“,mode=“phrase”,annotation_class=“user”)”
)
}   
{'RAW'}
其他的
{
fn:concat(
'字符串(',
$newQt,
“,mode=“simpleany”,annotation_class=“user”)”
)
}   
{'RAW'}
)
其他的
{$newQt}
{'AND'}

这个问题很难回答,因为我无法复制您的问题(我根本无法轻松让您的代码运行)。我也没有使用“oracle osb”,所以我不确定这是否会有很大帮助

我可以使用下面的xquery来完成我认为您正试图完成的任务。(我的处理器是Saxon HE xquery 9.3.0.4。我不必在函数上使用
fn:
前缀,但也许您可以在oracle中使用?)

XQuery

declare namespace stan = "http://notsurewhatthisis.com/stan";

let $qt := '"TEST"'
let $newQt := replace($qt,'"','\\"')
let $query :=
  if ($qt != '')
  then
    if (contains($qt,'"')) 
    then
      <stan:query>
        <stan:queryTerm type="phrase">{concat('string("',$newQt,'", mode="phrase", annotation_class="user")')}</stan:queryTerm>
        <stan:mode>RAW</stan:mode>
      </stan:query>
    else
      <stan:query>
        <stan:queryTerm type="phrase">{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>
return
  $query
<stan:query xmlns:stan="http://notsurewhatthisis.com/stan">
   <stan:queryTerm type="phrase">string("\"TEST\"", mode="phrase", annotation_class="user")</stan:queryTerm>
   <stan:mode>RAW</stan:mode>
</stan:query>
输出(将
$qt
更改为
后,让$qt:=''
这就是您的
如果($qt!='')那么,
将捕获的内容):


希望这能有所帮助。

要检查字符串是否包含双引号,请使用
fn:contains

fn:contains($string, '"')
您的代码区分三种情况,即

  • $qt是空字符串
  • $qt包含引号
  • $qt不带引号
我会这样写:

if ($qt = "") then
  <stan:query>
    <stan:queryTerm/>
    <stan:mode>AND</stan:mode>
  </stan:query>
else if (fn:contains($qt, '"'))then
  <stan:query>
    <stan:queryTerm>string("{fn:replace($qt, '"', '\\"')}", mode="phrase", annotation_class="user")</stan:queryTerm>
    <stan:mode>RAW</stan:mode>
  </stan:query>
else
  <stan:query>
    <stan:queryTerm>string("{$qt}", mode="simpleany", annotation_class="user")</stan:queryTerm>
    <stan:mode>RAW</stan:mode>
  </stan:query>
如果($qt=”“)那么
及
否则如果(fn:contains($qt,“')),则
字符串(“{fn:replace($qt,”,“\\”)}”,mode=“phrase”,annotation\u class=“user”)
未经加工的
其他的
字符串(“{$qt}”,mode=“simpleany”,annotation\u class=“user”)
未经加工的
一些额外的评论:

  • 您可以在其他元素内容中嵌入$qt或其衍生物,因此无需事先使用fn:concat组装它们
  • 构造stan:mode不需要嵌入表达式
  • 替换字符串中的反斜杠必须由另一个反斜杠转义,但这不能在其他任何地方进行
<stan:query xmlns:stan="http://notsurewhatthisis.com/stan">
   <stan:queryTerm/>
   <stan:mode>AND</stan:mode>
</stan:query>
fn:contains($string, '"')
if ($qt = "") then
  <stan:query>
    <stan:queryTerm/>
    <stan:mode>AND</stan:mode>
  </stan:query>
else if (fn:contains($qt, '"'))then
  <stan:query>
    <stan:queryTerm>string("{fn:replace($qt, '"', '\\"')}", mode="phrase", annotation_class="user")</stan:queryTerm>
    <stan:mode>RAW</stan:mode>
  </stan:query>
else
  <stan:query>
    <stan:queryTerm>string("{$qt}", mode="simpleany", annotation_class="user")</stan:queryTerm>
    <stan:mode>RAW</stan:mode>
  </stan:query>