OSB Xquery 在后面插入多个元素

OSB Xquery to insert multiple elements after

我收到 OSB 服务的回复如下:

<cus:GetAllCustomersResponse  xmlns:cus="http://www.waai.nl/cdm/customer"> 
          <cus:customerId>1</cus:customerId> 
          <cus:customerName>2</cus:customerName> 
</cus:GetAllCustomersResponse> 

我想在 OSB 代理的响应中的客户名称后插入几个元素。我可以通过 insert 做到这一点,但是如果有 20 个元素,我必须添加 20 个插入。您能否建议是否可以通过 OSB 代理中的 Xquery 完成此操作?

cus:GetAllCustomersResponse  xmlns:cus="http://www.waai.nl/cdm/customer"> 
          <cus:customerId>1</cus:customerId> 
          <cus:customerName>2</cus:customerName> 
          <cus:customerXXXXX>2</cus:customerXXXX> 
          <cus:customerXXYYY>2</cus:customerXXYYY>
          <cus:customerVVV>2</cus:customerVVV>
          <cus:customerBBB>2</cus:customerBBB>
          <cus:customerEEE>2</cus:customerEEE>
          ......
          ......
</cus:GetAllCustomersResponse> 

谢谢!!

可以,而且实际上是首选方法。您将需要阅读一些 FLWOR 表达式,但您最终会得到一些描述的 for 循环。

添加到 Trent 的正确答案中,这里有一个有用的 link 和示例代码 -

declare function local:insertEmpInfo($EmployeesIn as element()){

  copy $Employees := $EmployeesIn

 modify
  (

  for $employee in $Employees/EMP


   return (
            insert node <GENDER>M</GENDER> into $employee,
            insert node <LOC>IND</LOC> into $employee/LOC,
            insert node <ADDMORE>REPEAT_ME</ADDMORE> into $employee

           )
)

   return $Employees

 };

  declare function local:main () {

             let $EmployeesIn := <EMPS>
                                    <EMP>
                                      <ID>1</ID>
                                      <NAME>A</NAME>
                                      <LOC/>
                                    </EMP>
                                    <EMP>
                                      <ID>2</ID>
                                      <NAME>B</NAME>
                                      <LOC/>
                                    </EMP>
                                  </EMPS>

return local:insertEmpInfo($EmployeesIn)

  };

还有一点,转换表达式 (copy/modify) 仅在您使用 OSB 12+ 时才有效。

let $value := <foo><bar>hello</bar></foo>
return
   copy $new := $value
   modify (
     insert node <bat>world!</bat> as last into $new,
     replace value of node $new/bar with "Hello"
   )
   return $new

Returns:

<foo>
  <bar>Hello</bar>
  <bat>world!</bat>
</foo>

完整的细节在这里: https://www.w3.org/TR/xquery-update-10/

谢谢大家,找到了一种通过插入操作执行此操作的简单方法。在 cus:customerName

之后插入
  let $getAllCustomersResponse := 
  <GetAllCustomersResponse>
  <cus:customerXXXXX>2</cus:customerXXXX> 
  <cus:customerXXYYY>2</cus:customerXXYYY>
  <cus:customerVVV>2</cus:customerVVV>
   ............
   ............

  </GetAllCustomersResponse> 
  return
  $getAllCustomersResponse/*