[xquery-talk] Functions for printing path to a node

padmapriya ayyagari asn.padmapriya at gmail.com
Tue Dec 7 23:34:02 PST 2004


Hello,

Following are two xquery functions for printing the paths from root to
nodes returned as answer to xqueries. The argument to getPath is the
answer from an xquery which has been converted into an xml document
using hte document node constructor 'document { }'.


define function getPath($e as document) as xs:string
{
        for $n in $e
                return fn:string-join(fn:fullpath($n),"")

}

define function fullpath($n as node) as xs:string
 {
        if ($n/..) then concat('<',name($n), '>',
fullpath($n/..),"</",name($n),'>')
        else fn:data($n)
 }

However, when I execute the getPath function, it says : 

Exception in thread "main" galapi.GalapiException: Failure("Type
Error: Type declaration failed.  Type of value:
<xq:result/>
 does not match type:
xsd:string.

I even tried :

define function getPath($e as document) as document
{
        document {
        for $n in $e
                return fn:myPath($n)
        }

}

define function myPath($n as node) as element
 {
 if ($n/..) then element fn:name($node){myPath($n/..)}
 else fn:data($n)
 };

But I end up with a parse error.

What do you think is hte problem? Will this function serve the purpose
of printing the paths to nodes?

Thanks,
Padmapriya


More information about the talk mailing list