OSB XQuery Exception FORG0005: expected exactly one item, got 0 items

Oracle Serice Bus (OSB) XQuery Exception: FORG0005: expected exactly one item, got 0 items
OSB-Aktion “Ersetzen” beim Aktualisieren der Variable “response” nicht erfolgreich: com.bea.wli.common.xquery.XQueryException:
Fehler beim Parsen von XML: {err}FORG0005: expected exactly one item, got 0 items

https://forums.oracle.com/forums/thread.jspa?threadID=929438
This is one of the very basic errors in XQuery and XPath. This is thrown where an XPath is supposed to return a node but it can not retrieve one at runtime.
There can be many reasons for this.
For ex. your Xpath may be wrong, source XML does not contain the element which you are looking for, providing incorrect namespaces of the element.
You can log the input XML to verify that the element your XPath is referring to is present.
Then you can separately test the XPath/XQuery to validate its correctness.

http://eelzinga.wordpress.com/2009/07/17/oracle-service-bus-xquery-and-optional-parameters/
I need to be able to setup the parameters of the xquery as optional, like this i don’t need to evaluate every parameter in the xquery and can just pass the result of the xquery which is used for every parameter of the xquery.
see http://www.w3.org/TR/xquery/
“attribute()? refers to an optional attribute node”

Yes! this is the solution on Eric Elzinga blog entry “OSB XQuery and optional parameters”

Here, this is my Xquery Transformation (.xq) which I use on OSB.
Please pay attention to the eight “?” which I had to enter. Once on the function declaration (4 Parameters with ?) and once on the bottom when declaring the external variables (4 Variables with ?)
Without ? I allways get this strange “FORG0005: expected exactly one item, got 0 items” error.
After adding this mentioned 8 question marks, no more error appears!

(:: pragma bea:global-element-parameter parameter="$outputBankingSystem1" element="ns2:OutputBankingSystem" location="xxxx.xsd" ::)
(:: pragma bea:global-element-parameter parameter="$Money" element="ns0:MoneyTable" location="xxxx.xsd" ::)
(:: pragma bea:global-element-return element="ns4:getAccoutingResponse" location="xxxTypes_v0_6.xsd" ::)

declare namespace ns2 = "http://xmlns.oracle.com/pcbpel/adapter/db/.....";
...
...

declare function xf:doTransform($outputBankingSystem1 as element(ns2:OutputBankingSystem)?,
$Money as element(ns0:MoneyTable)?,
$errorServiceAvaloq as xs:string?,
$errorServiceFinnova as xs:string?)
as element(ns4:getAccoutingResponse)
{
<ns4:getAccoutingResponse schemaVersion="0.6">
{
<ns4:MoneyAccountList>
...
...
...
</ns4:MoneyAccountList>
}
</ns4:getAccoutingResponse>
};

declare variable $outputBankingSystem1 as element(ns2:OutputBankingSystem)? external;
declare variable $Money as element(ns0:MoneyTable)? external;
declare variable $errorServiceFinnova as xs:string? external;
declare variable $errorServiceAvaloq as xs:string? external;

xf:doTransform($outputBankingSystem1,
$Money,
$errorServiceFinnova,
$errorServiceAvaloq)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top