XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Glenn BrandSubject: Can I call an xquery file from another xquery file
Author: Glenn Brand
Date: 19 Mar 2007 02:18 PM
Originally Posted: 19 Mar 2007 02:08 AM
I want to create an xquery document that can call other xquery documents to process certain sections of an XML to XML transformation.

From time to time the source and target node mappings are different for a part of the XML input document. This happens when one party uses one element while another uses another element for the same purpose. I want the output to be consistent. This happens with X12 where several elements could be used to pass the data.

My idea is to build an xquery document like a composite object where each query file transforms one part of the input document. In the case where different elements are used in the input document by one party I would sort of override the file that does that transformation with another one particular to that party. That way the logic is less complicated especially if many parties are involved.

The xquery document management would be done externally.

Can this be done?

Postnext
Alberto MassariSubject: Can I call an xquery file from another xquery file
Author: Alberto Massari
Date: 19 Mar 2007 09:00 AM
Hi Glenn,
I don't know the kind of processing that you have in mind, so I can only give you a couple of suggestions.

1) XQuery documents can be modularized by creating modules, that expose functions that the main XQuery can invoke; so you could have a main XQuery that looks at the nodes of the source XML and invokes the appropriate module functions that can handle that specific kind of data. Note that the list of modules imported by the main XQuery cannot be changed at runtime, so the customization is done by writing a new main XQuery
2) if the processing that every XQuery performs is independent of the others (e.g. every XQuery generates a document that contains the nodes it cannot process, plus the transformation of those it can handle) you can create a pipeline where all the XQuery documents work on the result of the previous XQuery. The pipeline can be made more complex by adding routing nodes that, by inspecting the in-flight document, decide which XQuery processing should be performed.

Hope this helps,
Alberto

Postnext
Glenn BrandSubject: Can I call an xquery file from another xquery file
Author: Glenn Brand
Date: 19 Mar 2007 02:20 PM
Yes it does Alberto. Perfect.
Can you point me to any documents on both of those topics?

Postnext
Alberto MassariSubject: Can I call an xquery file from another xquery file
Author: Alberto Massari
Date: 20 Mar 2007 05:25 AM
Hi Glenn,
what I can tell you is very abstract, as I don't know much about the data you are manipulating, nor the kind of transformation you want to do.
So, take this example as a possible solution, that you will have to expand into a working one.

1) If you want to use XQuery modules, you should write single XQuery documents starting with

module namespace p = "namespace1";
declare function p:f($n as node()) as node()
{
(: your code that converts the $n node :)
};

(each module must have a different namespace) and then a main XQuery including them, and calling their functions accordingly

import module namespace p1 = "namespace1" at "module1.xquery";
import module namespace p2 = "namespace2" at "module2.xquery";

<result>{
for $i in /*
return
if(node-name($i)=fn:QName("","node1")) then p1:f($i)
else
if(node-name($i)=fn:QName("","node2")) then p2:f($i)
(: and so on... :)
else ()
}</result>

2) If you want to use pipelines (btw, you can learn about pipelines by watching the video at http://www.stylusstudio.com/videos/pipeline2/pipeline2.html) you should write several XQuery like this

declare function local:copier($n as node()) as node()*
{
for $i in $n/*
return
if(node-name($i)=fn:QName("","to-be-replaced")) then
()
else
element {node-name($i)}
{
for $a in $i/@*
return attribute {node-name($a)} {$a},
local:copier($i)
}
};

local:copier(.)

where each XQuery will take care of a single transformation; at this point, you can create a pipeline and drag the subset of XQuery documents you want to use, connect their input and output ports (you can add CHOOSE blocks to selectively enable some of them) and run it.

Hope this helps,
Alberto

Posttop
Glenn BrandSubject: Can I call an xquery file from another xquery file
Author: Glenn Brand
Date: 20 Mar 2007 03:17 PM
Originally Posted: 20 Mar 2007 03:16 PM
Yes it does. I have seen the video and it was very helpful. I will work with this and ask more questions as they come up.

Thanks Alberto.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.