【问题标题】:Xquery "replace bitmask value for given index" issue in Oracle Service BusOracle Service Bus 中的 Xquery“替换给定索引的位掩码值”问题
【发布时间】:2013-10-01 21:26:48
【问题描述】:

我正在尝试替换 32 位字符串变量。起初,所有值为“0”。

$bitmask:="00000000000000000000000000000000"

我有一些索引值,应该将这些索引中的值替换为“1”。

例如,我有索引值=(3,10)

预期的结果应该是;

$bitmask:="00100000010000000000000000000000"

实际上我做到了 :) 但我的位掩码值中有空格字符。我无法删除空格字符。

我的工作代码;

$serviceBits :=  tokenize('0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0',',')

<services>
{
for $t at $pos in $serviceBits
let  $temp := ''
return 
 if($pos = data($myElement/ns:position)) then
   concat($temp, '1')
 else  
   replace(concat($temp, $t)," ","")    
}
</services>

我的工作代码的结果是;

<services>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</services>

【问题讨论】:

    标签: replace xquery middleware bitmask osb


    【解决方案1】:

    您的代码中的问题是您将一个序列发布到新构造的元素中,该元素被序列化,其间有空格。在这里明确使用string-join

    <services>{
      string-join(
        (: all the other code for modification :),
        '' (: Nothing between the individual strings :)
      )
    }</services>
    

    无论如何,我不确定您在tokenize$bitmap 上的呼叫连接在哪里。

    要将数组转换为序列,调整一些值并再次返回字符串,请使用 string-to-codepoints 相应的 reverse 函数。它返回 unicode 代码点,从 0 变为 1 只需加 1。示例:

    let $bitmask := '00000000000000000000000000000000'
    return
      codepoints-to-string(
        for $char at $i in string-to-codepoints($bitmask)
        return
          if ($i = (3,10))
            then $char + 1
            else $char
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 2020-07-19
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      相关资源
      最近更新 更多