Subject:Using same xquery for 2 xml files Author:rajat nair Date:31 Jan 2008 12:29 PM Originally Posted: 31 Jan 2008 10:02 AM
Hi,
Thanks for the prompt reply,i m using java code that was generated from stylus studio enterprise edition from this xquery.The probelm is how do i pass/bind 2 incoming xml's to the XqPreparedExpression variable.I have attached my java code along with this post.Is is possible to pass more than 2 incoming xmls to get a single outgoing xml too??
public class tradetest3docs {
static String theDocumentBytes;
static String td;
static String t1d;
//private static Logger logger = Logger.getLogger(Quadesptest.class);
public static final String OAG_NAMESPACE_URI = "http://www.openapplications.org/oagis/9";
public static final Namespace OAG_NAMESPACE = Namespace.getNamespace("oag", OAG_NAMESPACE_URI);
public static final String ESB_BODY_XPATH_EXP = "/esb:Envelope/esb:Body";
public static void main(String[] args) throws Exception {
Subject:Using same xquery for 2 xml files Author:Minollo I. Date:31 Jan 2008 12:00 PM
You will need to use one or two external variables if you want to bind data from your Java application.
I find it more clear in this case to just use two external variables and not the static default input; so, I would change the query into:
declare variable $input1 as document-node(element(*, xs:untyped)) external;
declare variable $input2 as document-node(element(*, xs:untyped)) external;
<PurchaseOrderLine>
<LineNumber>
{ $input1/TradePowerRequest/RequestDetail/ItemLineNumber/text() }
</LineNumber>
{
for $RequestDetail in $input1/TradePowerRequest/RequestDetail
return
<items>
{
if($RequestDetail/ItemNumber/@source = "UI") then
<item1>
{ $input2/DetailAvailability/DisplaySequence/text() }
</item1>
else ()
}
</items>
}
</PurchaseOrderLine>
...and the Java code into... (btw, note that you don't need to use jdom at all; it's actually a much more performing and scalable solution not using it)
xqueryReader = new FileReader(new File(new URI(xqueryUri)));
DDXQDataSource dataSource = new DDXQDataSource();
dataSource.setOptions("serialize=indent=yes");
dataSource.setBaseUri(xqueryUri);
xqconnection = dataSource.getConnection();
// default input data type - this declares that the default context node is a document.
XQItemType type = xqconnection.createElementType(null, XQItemType.XQBASETYPE_UNTYPED);
XQItemType documentType = xqconnection.createDocumentElementType(type);
XQStaticContext context = xqconnection.getStaticContext();
context.setContextItemStaticType(documentType);
context.setBindingMode(XQConstants.BINDING_MODE_DEFERRED);
xqconnection.setStaticContext(context);