使用Xquery替换XML Distinct-Values Oracle Service Bus 11G

时间:2015-04-12 10:08:25

标签: xml replace xquery osb distinct-values

如何为不同的值案例替换XML结果?

我得到了值groupId,但我想将其替换为groupName,客户可以将其替换为不仅仅是数字。



<TestList>
  <Test>
    <number>1000</number>
    <groupId>2323</groupId>
  </Test>
  <Test>
    <number>2000</number>
    <groupId>3434</groupId>
  </Test>
  <Test>
    <number>3000</number>
    <groupId>2323</groupId>
  </Test>
  <Test>
    <number>4000</number>
    <groupId>4444</groupId>
  </Test>
</TestList>
&#13;
&#13;
&#13;

预期结果

&#13;
&#13;
<TestList>
  <Test>
    <number>1000</number>
    <groupId>Group 1</groupId>
  </Test>
  <Test>
    <number>2000</number>
    <groupId>Group 2</groupId>
  </Test>
  <Test>
    <number>3000</number>
    <groupId>Group 1</groupId>
  </Test>
  <Test>
    <number>4000</number>
    <groupId>Group 3</groupId>
  </Test>
</TestList>
&#13;
&#13;
&#13;

谢谢,

ANDREE

1 个答案:

答案 0 :(得分:0)

在11g中,我认为您可以通过扩展使用BEA组。尝试这样的事情:

declare variable $data :=
<TestList>
  <Test>
    <number>1000</number>
    <groupId>2323</groupId>
  </Test>
  <Test>
    <number>2000</number>
    <groupId>3434</groupId>
  </Test>
  <Test>
    <number>3000</number>
    <groupId>2323</groupId>
  </Test>
  <Test>
    <number>4000</number>
    <groupId>4444</groupId>
  </Test>
</TestList>;

<TestList>{
  let $groups :=
    for $test in $data/Test
    group $test as $testGroup by $test/groupId as $groupId
    return
      <group>{$testGroup}</group>
  for $group at $pos in $groups,
      $test in $group/Test
  return
    <Test>
      {$test/number}
      <groupId>{$pos}</groupId>
    </Test>
}</TestList>