[xquery-talk] How to run xquery dynamically on file listing from directory

Wei, Alice J. ajwei at indiana.edu
Sat Apr 12 17:35:56 PDT 2008

From: Kevin Grover [kevin at kevingrover.net]
Sent: Thursday, April 10, 2008 9:00 PM
To: seleneplatt at comcast.net
Cc: talk at x-query.com
Subject: Re: [xquery-talk] How to run xquery dynamically on file listing from   directory

On Thu, Apr 10, 2008 at 11:22 AM,  <seleneplatt at comcast.net> wrote:
> I'm a complete newbie at xquery and am trying to execute a query dynamically on
>  all files in a given directory, rather than hardcoding a particular file into
>  the 'doc()' call.  I've tried using 'collection()' but am unclear as to how to
>  get it to work.
>  I did see this thread on x-query.com:
>  [xquery-talk] Query Through Multiple Files
>  but the closest anyone came to the answer I was hoping to find was to hardcode a
>  *list* of files to traverse.
>  Is there anyway to do something like:
>     for $x in collection("xmlfiles")
>  where 'xmlfiles' is a subdirectory containing the actual xml files I want to
>  use?  I would need to know the exact syntax, as this is all new to me.
>  Thanks!

I feel for you on this.  It's taken me weeks to figure anything out.
The crux if it is that the 'collection()' function is implementation

I've been trying with saxon for a long while and could not find any
documentation or examples.  After many attempts at searching (Google),
 and some dumb luck (I searched the main saxon documentation toc  for
collection), I found saxon's documentation page:


Still, no examples, but better.  From that page, I think I can
probably get my stuff going.  What I wanted to do at the time was more
of a small itch than and real need, so I tended to look into it
somewhat shallowly and sporadialy.

NOTE: I was stuck with a non Internet connected machine, so I had to
search later, from other machines.  I tried downloading the saxon
documentation, but all seemed incomplete.  I grabbed saxon9, and just
recently grabbed it's doc distro, but have not tried to search it for
this.  Maybe I will.  I would (personally) like to see the Saxon
Documentation rendered into many forms (PDF, HTML, CHM) from something
like DocBook.  It would also be _very_ helpful if there were more
examples.  I've been meaning to ask if I could help do this (at least
to convert the HTML documentation tree to DocBook), but never got
around to it.

If you're using an all-in-one editor, you'll have to dig into it to
see what back end they use.  I believe oXygen XML uses Saxon (but I'm
not certain).

Yes, oXygen does support Saxon. Using something like collection("somefiledirectory") that contains all XML files should be able to get something you wanted. Unless, you want other things along with it, which then you might have to show what you got so far.

This is one of those things that seems sort of simple when I find the
answer, but was completely baffling beforehand - particularly since I
could not seem to find anything online.

I have to agree that right now there are some thing that ought to be simple enough, but since XQuery is so new, there are not that many examples for every use case

Hope this helps.

Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu

More information about the talk mailing list