Duckling
Duckling

Reputation: 71

XQuery pass argument to function

I want to pass a XML Document as an argument to a function called evaluate:

declare function my_namespace:evaluate($tree as element()) as element(fraction{
     do something}

I tried it with doc(), but it returns a document-node and I can't cast it to be an element. Can somebody tell me how to read an XML file as element, so I can pass it to my function?

I tried:

for $tree in doc("baum.xml")
let $tree :=$tree treat as element()
return $tree

and:

let $tree := document("baum.xml")

Upvotes: 1

Views: 439

Answers (1)

Christian Grün
Christian Grün

Reputation: 6229

A document node has a single root element as child. You can use a simple child step to pass this root element on to your function:

let $tree := doc("baum.xml")/*
return my_namespace:evaluate($tree)

Upvotes: 3

Related Questions