Setting base-dir for xquery:eval
Thursday, 18 February 2016 · 6 messages · last reply 19 Feb 2016
MG
Marc van Grootel18 Feb 2016 22:29 #
Hi,
I am having quite some fun with
xquery:eval. I am working on a little module for executable documentation (similar to Python doctest). I want to write documentation in asciidoc, parse it and execute source code blocks inside the asciidoc. Parsing works by calling asciidocj and so far I can run simple queries, evaluate them, compare them with an expected outcome and write the result back as evaluated asciidoc.
Now I want to tackle more advanced queries that import modules. But when running xquery:eval with a string it will try to resolve paths relative to the code module and not relative to the file the string came from. Ideally I would like to be able to set the base-dir for xquery:eval. The asciidoc file isn't always in the correct path relative to the module that I need to import.
Other options I'm considering but are less ideal.
- Manipulate the module import paths in the query string using regexps
- Writing out to a temp file and then use xquery:parse-uri (but this is tricky as I may not want to clutter existing directories with tempfiles only to have the imports work).
Unless there are better options I think I'll opt for string massaging using regexps. But maybe someone has a better idea.
--MarcCG
Christian Grün18 Feb 2016 23:38 #
Hi Marc,
Quoted text · Marc van Grootel · 3 lines
> when running xquery:eval with a string it will try to resolve paths > relative to the code module and not relative to the file the string > came from.
You could add a base-uri declaration in your query:
let $uri := 'a/b/c'
let $query := '1'
return xquery:eval(
'declare base-uri "' || $uri || '"; ' || $query
)Does this help?
Christian
Quoted text · Marc van Grootel · 15 lines
> Ideally I would like to be able to set the base-dir for > xquery:eval. The asciidoc file isn't always in the correct path > relative to the module that I need to import. > > Other options I'm considering but are less ideal. > > - Manipulate the module import paths in the query string using regexps > - Writing out to a temp file and then use xquery:parse-uri (but this > is tricky as I may not want to clutter existing directories with > tempfiles only to have the imports work). > > Unless there are better options I think I'll opt for string massaging > using regexps. But maybe someone has a better idea. > > --Marc
MG
Marc van Grootel19 Feb 2016 00:10 #
Yes, exactly what I was after. Thanks and good night :)
--Marc
Quoted text · Christian Grün · 35 lines
> On 18 feb. 2016, at 23:38, Christian Grün <christian.gruen at gmail.com> wrote: > > Hi Marc, > >> when running xquery:eval with a string it will try to resolve paths >> relative to the code module and not relative to the file the string >> came from. > > You could add a base-uri declaration in your query: > > let $uri := 'a/b/c' > let $query := '1' > return xquery:eval( > 'declare base-uri "' || $uri || '"; ' || $query > ) > > Does this help? > Christian > > >> Ideally I would like to be able to set the base-dir for >> xquery:eval. The asciidoc file isn't always in the correct path >> relative to the module that I need to import. >> >> Other options I'm considering but are less ideal. >> >> - Manipulate the module import paths in the query string using regexps >> - Writing out to a temp file and then use xquery:parse-uri (but this >> is tricky as I may not want to clutter existing directories with >> tempfiles only to have the imports work). >> >> Unless there are better options I think I'll opt for string massaging >> using regexps. But maybe someone has a better idea. >> >> --Marc
AB
Andy Bunce19 Feb 2016 03:18 #
Hi Christian,
I have used this technique and it works unless the query string already has a base-uri set. I wonder if there is a case for adding base-uri to the
xquery:eval options map to handle this in a cleaner way?
/AndyQuoted text · Marc van Grootel · 42 lines
On 19 Feb 2016 07:10, "Marc van Grootel" <marc.van.grootel at gmail.com> wrote: > Yes, exactly what I was after. Thanks and good night :) > > --Marc > > > On 18 feb. 2016, at 23:38, Christian Grün <christian.gruen at gmail.com> > wrote: > > > > Hi Marc, > > > >> when running xquery:eval with a string it will try to resolve paths > >> relative to the code module and not relative to the file the string > >> came from. > > > > You could add a base-uri declaration in your query: > > > > let $uri := 'a/b/c' > > let $query := '1' > > return xquery:eval( > > 'declare base-uri "' || $uri || '"; ' || $query > > ) > > > > Does this help? > > Christian > > > > > >> Ideally I would like to be able to set the base-dir for > >> xquery:eval. The asciidoc file isn't always in the correct path > >> relative to the module that I need to import. > >> > >> Other options I'm considering but are less ideal. > >> > >> - Manipulate the module import paths in the query string using regexps > >> - Writing out to a temp file and then use xquery:parse-uri (but this > >> is tricky as I may not want to clutter existing directories with > >> tempfiles only to have the imports work). > >> > >> Unless there are better options I think I'll opt for string massaging > >> using regexps. But maybe someone has a better idea. > >> > >> --Marc >
CG
Christian Grün19 Feb 2016 09:51 #
Quoted text · Andy Bunce · 2 lines
> a base-uri set. I wonder if there is a case for adding base-uri to the > xquery:eval options map to handle this in a cleaner way?
…now there is [1,2]. New features in the documentation will be marked with 8.5, but they will already available in the snapshots and patch versions.
[1] http://docs.basex.org/wiki/XQuery_Module#xquery:eval
[2] http://files.basex.org/releases/latest/
Quoted text · Marc van Grootel · 42 lines
> On 19 Feb 2016 07:10, "Marc van Grootel" <marc.van.grootel at gmail.com> wrote: >> >> Yes, exactly what I was after. Thanks and good night :) >> >> --Marc >> >> > On 18 feb. 2016, at 23:38, Christian Grün <christian.gruen at gmail.com> >> > wrote: >> > >> > Hi Marc, >> > >> >> when running xquery:eval with a string it will try to resolve paths >> >> relative to the code module and not relative to the file the string >> >> came from. >> > >> > You could add a base-uri declaration in your query: >> > >> > let $uri := 'a/b/c' >> > let $query := '1' >> > return xquery:eval( >> > 'declare base-uri "' || $uri || '"; ' || $query >> > ) >> > >> > Does this help? >> > Christian >> > >> > >> >> Ideally I would like to be able to set the base-dir for >> >> xquery:eval. The asciidoc file isn't always in the correct path >> >> relative to the module that I need to import. >> >> >> >> Other options I'm considering but are less ideal. >> >> >> >> - Manipulate the module import paths in the query string using regexps >> >> - Writing out to a temp file and then use xquery:parse-uri (but this >> >> is tricky as I may not want to clutter existing directories with >> >> tempfiles only to have the imports work). >> >> >> >> Unless there are better options I think I'll opt for string massaging >> >> using regexps. But maybe someone has a better idea. >> >> >> >> --Marc
MG
Marc van Grootel19 Feb 2016 10:15 #
Wow. You guys don't stop to amaze. Chris's suggestion would've worked. Andy's suggestion was what I actually had in mind when I wrote the post.
So he reads my mind, Chris adds a new feature and all that before the clock of 10 less than 12 hours after the post. And that, probably, with a good night's sleep in between.
Of course I'll share what I have. I am creating it to better provide testable documentation and examples for Origami (I'm still working on it but work has kinda taken over the last few months).
Cheers,
--Marc
Quoted text · Christian Grün · 56 lines
On Fri, Feb 19, 2016 at 9:51 AM, Christian Grün <christian.gruen at gmail.com> wrote: >> a base-uri set. I wonder if there is a case for adding base-uri to the >> xquery:eval options map to handle this in a cleaner way? > > …now there is [1,2]. New features in the documentation will be marked > with 8.5, but they will already available in the snapshots and patch > versions. > > [1] http://docs.basex.org/wiki/XQuery_Module#xquery:eval > [2] http://files.basex.org/releases/latest/ > > > >> On 19 Feb 2016 07:10, "Marc van Grootel" <marc.van.grootel at gmail.com> wrote: >>> >>> Yes, exactly what I was after. Thanks and good night :) >>> >>> --Marc >>> >>> > On 18 feb. 2016, at 23:38, Christian Grün <christian.gruen at gmail.com> >>> > wrote: >>> > >>> > Hi Marc, >>> > >>> >> when running xquery:eval with a string it will try to resolve paths >>> >> relative to the code module and not relative to the file the string >>> >> came from. >>> > >>> > You could add a base-uri declaration in your query: >>> > >>> > let $uri := 'a/b/c' >>> > let $query := '1' >>> > return xquery:eval( >>> > 'declare base-uri "' || $uri || '"; ' || $query >>> > ) >>> > >>> > Does this help? >>> > Christian >>> > >>> > >>> >> Ideally I would like to be able to set the base-dir for >>> >> xquery:eval. The asciidoc file isn't always in the correct path >>> >> relative to the module that I need to import. >>> >> >>> >> Other options I'm considering but are less ideal. >>> >> >>> >> - Manipulate the module import paths in the query string using regexps >>> >> - Writing out to a temp file and then use xquery:parse-uri (but this >>> >> is tricky as I may not want to clutter existing directories with >>> >> tempfiles only to have the imports work). >>> >> >>> >> Unless there are better options I think I'll opt for string massaging >>> >> using regexps. But maybe someone has a better idea. >>> >> >>> >> --Marc
--
--Marc
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery