[xquery-talk] Using axis in XQuery

Michael Kay mhk at mhk.me.uk
Wed Dec 1 09:26:14 PST 2004


> 
> This is one way
> 
> declare function local:fullpath($node as node())
> {
> 	if (name($node)) then 
> 		concat(name($node), '/', local:fullpath($node/..))
> 	else ()
> };
> 
> Ivan

This will fail with a type error if applied to a node in a tree whose root
is an element rather than a document node (it will call itself with an empty
sequence as the argument value). In a static-typing implementation it will
fail with a static type error because of this possibility.

You can solve the first problem by making the terminating condition

if ($node/..) then

It would also be cleaner to make the else branch return "" rather than (),
and to declare the return type as xs:string. 

Michael Kay
http://www.saxonica.com/




More information about the talk mailing list