|
next
|
 Subject: Can I call an xquery file from another xquery file Author: (Deleted User) 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
|
|
|