tags:

views:

115

answers:

1

I'm using Oxygen XML to to work with an XML file that contains references to other XML files. These other XML files are stored in a subdirectory of the directory that contains the main XML file.

Downloads/
directory1/
  main.xml
  subdirectory1/
    other1.xml
    other2.xml

The locations of the other XML files are stored as relative links within the main file. My query looks like something this:

for $df in /clldata/DiscussionForums/DiscussionForum
    let $href := replace(data($df/@href),"\\","/")
    for $p in doc($href)
return $p

The problem I've run into is that Oxygen uses the path to the xquery file as the base for the relative path, obviously resulting in file not found errors. How can I get the path to the XML document within my query?

Right now I'm just using concat() to prepend the correct path but I want this to be easily reusable.

+1  A: 

You need to resolve the URI relative to the URI of the main XML document. In your case, you probably want to do something like:

let $href = resolve-uri($d/@href, base-uri($d))

Here, the base-uri($d) function is getting the absolute URI of the source document containing the relevant DiscussionForum node, and the resolve-uri is resolving the new URI relative to this.

This works for me using SAXON on the jedit XQuery plugin. YMMV, I've never used Oxygen XML.

Peter Hart