Oracle OSM - XQuery doesn't loop

不羁的心 提交于 2019-12-11 04:53:44

问题


I'm using OSM 7.2.0.3 and I have cartridge with an Order Recognition Rule, with its Order Data Rule (inside Transformation tab)

In the ODR I have this XQuery code:

declare namespace im="http://xxx"; 
declare namespace xs="http://www.w3.org/2001/XMLSchema";

declare variable $ord :=  fn:root(.)/im:Order;

<_root>
  <Order>
  {
    for $moli in $ord/MainOrderLineItem
      return 
        $moli/LineItemAttributeInfo/LineItemAttribute
  }
 </Order>
</_root>

The XML input to the OSM is:

<ord:CreateOrder
    xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
    <im:Order xmlns:im="http://xxx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.oracle.com/communications/sce/dictionary/BaseOrderCommonCartridge/DataDictionary_BaseOrderCommon ../dataDictionary/DataDictionary_BaseOrderCommon.xsd">

      <OrderHeader>
        <OrderID>12345</OrderID>
        <RevisionNumber>1</RevisionNumber>
      </OrderHeader>

      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>1234</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>
      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>5678</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>
      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>abcd</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>

    </im:Order>
</ord:CreateOrder>

There are 3 occurences of <MainOrderLineItem>'s but the output is only 1:

<LineItemAttribute xmlns:im="http://xxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <AttributeID>1234</AttributeID>
</LineItemAttributeInfo>

Why is it not looping?

Thanks a lot for your replies.


回答1:


The problem is here:

declare variable $ord :=  fn:root(.)/im:Order;

Must be:

declare variable $ord :=  fn:root(.)/*/im:Order;



回答2:


This is probably way too late a reply, but most likely the issue was with node selection expression in the for statement. The correct way to select multiple MainOrderLineItems :

for $moli in $ord//MainOrderLineItem

Notice the double forward slashes after $ord

'/abcde' path expression selects the root element 'abcde'

'parent//abcde' path expression selects all the child elements named 'abcde' under parent

Since multiple MainOrderLineItem nodes are present, the path expression needs to include '//'




回答3:


I just used your XQuery and checked, it is fine. Try to print out the $ord variable in console to see what you are actually getting in OSM.

this is what I tried in any XQuery ide:

declare namespace im="http://xxx"; 

declare variable $ord1 := <ord:CreateOrder
    xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
    <im:Order xmlns:im="http://xxx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.oracle.com/communications/sce/dictionary/BaseOrderCommonCartridge/DataDictionary_BaseOrderCommon ../dataDictionary/DataDictionary_BaseOrderCommon.xsd">

      <OrderHeader>
        <OrderID>12345</OrderID>
        <RevisionNumber>1</RevisionNumber>
      </OrderHeader>

      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>1234</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>
      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>5678</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>
      <MainOrderLineItem>
        <LineItemAttributeInfo>
          <LineItemAttribute>
            <AttributeID>abcd</AttributeID>
          </LineItemAttribute>
        </LineItemAttributeInfo>
      </MainOrderLineItem>
    </im:Order>
</ord:CreateOrder>;

let $ord := $ord1/im:Order

return
(
    for $moli in $ord/MainOrderLineItem
      return 
        $moli/LineItemAttributeInfo/LineItemAttribute
)

and the result is as expected only..

<LineItemAttribute xmlns:im="http://xxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
  <AttributeID>1234</AttributeID>
</LineItemAttribute>
<LineItemAttribute xmlns:im="http://xxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
  <AttributeID>5678</AttributeID>
</LineItemAttribute>
<LineItemAttribute xmlns:im="http://xxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
  <AttributeID>abcd</AttributeID>
</LineItemAttribute>


来源:https://stackoverflow.com/questions/13028792/oracle-osm-xquery-doesnt-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!