Querying path structure from node A to node X

I am trying to formulate a query which will return the structured path from a node A to a node X which is burried in the hierarchy under node A.

for example

Hierarchy :

<cap>
  <name>A</name>
  <children>
    <cap>
       <name>B</name>
    </cap>
    <cap>
       <name>C</name>
       <children>
          <cap>
             <name>D</name>
          </cap>
          <cap>
             <name>E</name>
             <children>
                <cap>
                   <name>X</name>
                </cap>
             </children>
          </cap>
       </children>
    </cap>
  </children>
</cap>
</pre><BR><BR><BR>what i would like result to be is the following <BR><BR><pre class="ip-ubbcode-code-pre"> 
<cap>
  <name>A</name>
  <cap>
     <name>C</name>
     <cap>
       <name>E</name>
       <cap>
         <name>X</name>
       </cap>
     </cap>
  </cap>
</cap>




Ultimately the query will be operating on a hierachy where each node has an ID. A root node ID and a leaf node ID will be specified and the structured path between the two nodes will be returned.

Attached is a more extensive sample data set that I am working with

test input - root ID : dg8i2d0g
- leaf ID : dfyfmsq3


Thank you in advance for any help.


–joeycz

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

XML_hierarchy.xml (66.5 KB)

The following query is what i have formulated but it dose not quite do what i would like it to do. The hierachy is generated but its in reverse order.

The root of the generated structure should be the leaf and vice versa.

How would i be able to reverse the order?

  
define function recurse(element $cap, xs:string $root_id ) returns element{
<Capability>
{$cap/@id, $cap/name, $cap/priority}
{
	
	if (string($root_id) != string($cap/@id))  
	then 
	  for $parent in $cap/../..
             return recurse($parent, $root_id)
	else
          ()
}
</Capability>

}

let $root_id := "dg8i2d0g"
for $capability in document("XML_hierarchy.xml")/Hierarchy//Capability where $capability/@id = "dfyfmsq3"
return recurse($capability, $root_id) 




Thanks …

–joeycz

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

I managed to figure out the query by trial and error which will return the result that I was looking for

Follwing is the query:

  
define function recurse(element $cap, xs:string $leaf_id ) returns element{
	
	if (string($leaf_id) = string($cap/@id))  
	then
	   <Capability>
		{$cap/@id, $cap/name, $cap/priority}
		<siblings>{count($cap/../Capability)}</siblings>
	   </Capability>
	else
	  for $child in $cap/collection/Capability
		let $e := recurse($child, $leaf_id)
		return if(empty($e)) then ()
		else
		   <Capability>
			{$cap/@id, $cap/name, $cap/priority}
			<siblings>{count($cap/../Capability)}</siblings>
			{$e}
	   	   </Capability>
}

define function ROI_Query($root_id, $leaf_id, $file){
	for $capability in document($file)/Hierarchy//Capability where $capability/@id = $root_id
	return recurse($capability, $leaf_id) 
}




Question:
When will Tamino support these kinds of queries?

I am currently using a Java wrapper arround Quip to perform this query on data from Tamino. It sorta defeats the purpose of the Java Tamino API, but this is the only way I have be able to achieve the results that I needed. It would be realy nice if Tamino had a way to define user functions.

Another Question:
How are function in the tf: namespace defined. They haveto be implemeted somewhere. Going down that route, would one be able to define some functions and make them availble thourgh the Tamino XQuery interface?


Thanks

–joeycz

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1