"your query returned an empty sequence"

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
whanley
Posts: 3

"your query returned an empty sequence"

Thu Mar 23, 2017 6:22 pm

I'm an XQuery beginner.

When I run a query like

Code: Select all

declare default element namespace "https://github.com/dig-eg-gaz/content";
for $a in doc("1905-01-06.xml")
return $a//head


I get this error message: "your query returned an empty sequence"

When I run it as

Code: Select all

declare default element namespace "https://github.com/dig-eg-gaz/content";
for $a in doc("1905-01-06.xml")
return $a


i.e., without "//head", it returns the whole xml document.

Help?
adrian
Posts: 2443

Re: "your query returned an empty sequence"

Fri Mar 24, 2017 11:51 am

Hi,

What about if you use:

Code: Select all

return $a//*:head
If this works, check the namespace of "head" in the XML file.

BTW, not sure what you're trying to accomplish, but that 'for' seems pointless on the doc() with one file.
Maybe you wanted to iterate on the head elements?
Like this:

Code: Select all

declare default element namespace "https://github.com/dig-eg-gaz/content";
for $a in doc("1905-01-06.xml")//head
return $a

Actually if you're not doing anything in the for, you might as well not use it:

Code: Select all

doc("1905-01-06.xml")//head

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
whanley
Posts: 3

Re: "your query returned an empty sequence"

Fri Mar 24, 2017 3:56 pm

Thanks, Adrian. This is helpful. I guess I don't understand how namespaces work in XQuery, but *:head seems to work fine provisionally, as you suggested.

What I'm trying to do is return various results from about 300 TEI/XML files in a github repository ("https://github.com/dig-eg-gaz/content"). I've been querying these files as a project in Oxygen using XPath; that works fine, but I'm trying to figure out how to do some more complex queries.

I've spent quite a while looking at XQuery tutorials, but I seem not to be able to return results from my whole repository. All I can manage is to return results from one doc at a time, either by specifying it as doc("1905-05-06.xml") or opening the doc in Oxygen.

Sorry to ask such basic questions but I'd be grateful for any assistance.

Yours,
Will
adrian
Posts: 2443

Re: "your query returned an empty sequence"

Fri Mar 24, 2017 5:56 pm

Hi,

You need to use collection() to work on multiple XML files, but I'm not sure how you could do that directly on the github repository. The problem is obtaining the list of files from the github repository (full URLs). If you have that, you could iterate over them.

If the repository is in a folder from the local file system and you're using Saxon 9, you can use collection() like this:

Code: Select all

for $a in collection("file:/C:/path/to/my/files/?select=*.xml;recurse=yes")
return $a

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
whanley
Posts: 3

Re: "your query returned an empty sequence"

Thu Mar 30, 2017 8:26 pm

Thanks, collection() was what I needed. I've got a lot to learn, but you've put me on the right track.

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 1 guest