XQuery Nested loop error

739 Views Asked by At

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 $order := fn:root(.)/im:Order;

<_root>
  <Order>
  {
    for $moli in $order/MainOrderLineItem
      return {
        <OrderLineItem>
          {$moli/LineItemAttributeInfo/LineItemAttribute}
        </OrderLineItem>
        {
          for $oli in $moli/OrderLineItem
          return 
            <OrderLineItem>
              {$oli/LineItemAttributeInfo/LineItemAttribute}
            </OrderLineItem>
        }
      }
  }
  </Order>
</_root>

There's no compile error in OSM, but on runtime I get:

Invalid Order Specification Fault
Order data expression failed due to oracle.communications.ordermanagement.rule.XMLRuleException

I run the OSM by submitting an XML through Web Service.

Thanks a lot for your replies.

1

There are 1 best solutions below

0
On BEST ANSWER

The returned XML should actually be in parentheses instead of braces. There also needs to be a comma between the first returned OrderLineItem element and the FLWOR expression instead of wrapping it in braces:

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

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

<_root>
  <Order>{
    for $moli in $order/MainOrderLineItem
    return (
      <OrderLineItem>
        {$moli/LineItemAttributeInfo/LineItemAttribute}
      </OrderLineItem>,
      for $oli in $moli/OrderLineItem
      return 
        <OrderLineItem>
          {$oli/LineItemAttributeInfo/LineItemAttribute}
        </OrderLineItem>
    )
  }</Order>
</_root>