I have an XQuery query where I create an XHTML document out of data stored in XML. The XML looks like this:
<document>
<div>
<head>name-I-should-display</head>
<!-- more data -->
</div>
<div>
<head>name-of-div-2</head>
<!-- more data -->
</div>
<!-- more divs -->
</document>
In my xquery, I can retrieve the XML document fine:
let $mydoc := doc("my-xml-file.xml")
I can get the "document" node like this:
let $rootnode := $mydoc/*[1]
but if I try this:
let $rootnode := $mydoc/document
I get nothing. When I get the "document" node with the first form, the divs behave the same way. I'm very new to XQuery but I know this should work as it already had in another query on a document with a very similar structure.
Additional information that could help:
- used program is BaseX 9.0.2 on linux
- I'm using the
/name()
function to determine whether or not I have retrieved the node I wanted to or retrieved null - the XML file has an XSLT stylesheet declaration at the beginning, the similar file that had worked this way didn't have one
- I cannot modify the XML file
What could have gone wrong?
let $rootnode := $mydoc/*[name()='document']
? – Anderssonlet $rootnode := $mydoc/*[local-name()='document']
. If that works (andname()
doesn't), you most likely have a default namespace you're not showing in your example. – Daniel Haley