Make external variable declarations mandatory #833

Saturday, 1 February 2014 · 5 messages
JM
jean-marc Mercier1 Feb 2014 09:16 #
Hi, I am extensively using a function wrapping xquery:eval. My use case is roughly the following :
declare function local:eval_helper($exp,
$args){xquery:eval('$xml'||$exp,map{'$xml' := $args})};
declare variable $test := <toto><tata>1</tata></toto>;
local:eval_helper3('//tata', $test)
Since the following correction : [1] https://github.com/BaseXdb/basex/issues/833, the previous code raises now a [XPST0008] Undefined variable $xml. I have tried several combinations to find a workaround, none are working :
- declare function local:eval_helper($exp,
$args){xquery:eval(''||$exp,map{'' := $args})};
([XPDY0050] Root of the context item must be a document node.).
- declare function local:eval_helper($exp, $args){xquery:evaluate($arg||$exp)};
[XPTY0019] Steps within a path expression must yield nodes; xs:integer found. -- declare variable $xml external := "xml", : [XPST0008] Undefined variable $xml. What is the correct workaround ? Cheers Jean-Marc
DK
Dirk Kirsten1 Feb 2014 10:34 #
Hi Jean-Marc, external variables now have to be explicitly declared. You can do so by:
    declare variable $xml external;
Cheers, Dirk
Quoted text · jean-marc Mercier · 42 lines
On 01/02/14 09:16, jean-marc Mercier wrote: > Hi, > > I am extensively using a function wrapping xquery:eval. My use case is > roughly the following : > > declare function local:eval_helper($exp, > $args){xquery:eval('$xml'||$exp,map{'$xml' := $args})}; > declare variable $test := <toto><tata>1</tata></toto>; > local:eval_helper3('//tata', $test) > > > Since the following correction : [1] > https://github.com/BaseXdb/basex/issues/833, the previous code raises now a > [XPST0008] Undefined variable $xml. > > I have tried several combinations to find a workaround, none are working : > > - declare function local:eval_helper($exp, > $args){xquery:eval(''||$exp,map{'' := $args})}; > ([XPDY0050] Root of the context item must be a document node.). > - declare function local:eval_helper($exp, $args){xquery:evaluate($arg||$exp)}; > > [XPTY0019] Steps within a path expression must yield nodes; xs:integer > found. > -- declare variable $xml external := "xml", : [XPST0008] Undefined variable > $xml. > > What is the correct workaround ? > > > Cheers > > Jean-Marc > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
JM
jean-marc Mercier1 Feb 2014 11:44 #
Dirkk, thx for your answer. I am really sorry, but definitively, I don't know how to use xquery:eval with the last release. Following your advise, I tried the following one, but it does not work:
declare function local:eval_helper($exp, $args){
    let $query := 'declare variable $xml external; $xml'
    let $vars  := map { '$xml':= $args }
    return
    xquery:eval('$xml'||$exp,$vars)
};
declare variable $test := <toto><tata>1</tata></toto>;
local:eval_helper('//tata', $test)
Could you try yourself ? I mean, can you make the above user case working ? This use case worked fineley with BaseX7.8 beta 6aeaebf, before the external variable correction. 2014-02-01 Dirk Kirsten <dk at basex.org>:
Quoted text · Dirk Kirsten · 67 lines
> Hi Jean-Marc, > > external variables now have to be explicitly declared. You can do so by: > > declare variable $xml external; > > Cheers, > Dirk > > On 01/02/14 09:16, jean-marc Mercier wrote: > > Hi, > > > > I am extensively using a function wrapping xquery:eval. My use case is > > roughly the following : > > > > declare function local:eval_helper($exp, > > $args){xquery:eval('$xml'||$exp,map{'$xml' := $args})}; > > declare variable $test := <toto><tata>1</tata></toto>; > > local:eval_helper3('//tata', $test) > > > > > > Since the following correction : [1] > > https://github.com/BaseXdb/basex/issues/833, the previous code raises > now a > > [XPST0008] Undefined variable $xml. > > > > I have tried several combinations to find a workaround, none are working > : > > > > - declare function local:eval_helper($exp, > > $args){xquery:eval(''||$exp,map{'' := $args})}; > > ([XPDY0050] Root of the context item must be a document node.). > > - declare function local:eval_helper($exp, > $args){xquery:evaluate($arg||$exp)}; > > > > [XPTY0019] Steps within a path expression must yield nodes; xs:integer > > found. > > -- declare variable $xml external := "xml", : [XPST0008] Undefined > variable > > $xml. > > > > What is the correct workaround ? > > > > > > Cheers > > > > Jean-Marc > > > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grün1 Feb 2014 11:48 #
Hi Jean-Marc (answering on behalf of Dirk... Let's see who is faster ;), your query will work if you change the xquery:eval call as follows:
    xquery:eval($query || $exp,$vars)
Best, Christian
Quoted text · jean-marc Mercier · 102 lines
On Sat, Feb 1, 2014 at 11:44 AM, jean-marc Mercier < jeanmarc.mercier at gmail.com> wrote: > Dirkk, thx for your answer. > > I am really sorry, but definitively, I don't know how to use xquery:eval > with the last release. > > Following your advise, I tried the following one, but it does not work: > > declare function local:eval_helper($exp, $args){ > let $query := 'declare variable $xml external; $xml' > let $vars := map { '$xml':= $args } > return > xquery:eval('$xml'||$exp,$vars) > }; > declare variable $test := <toto><tata>1</tata></toto>; > local:eval_helper('//tata', $test) > > Could you try yourself ? I mean, can you make the above user case working > ? This use case worked fineley with BaseX7.8 beta 6aeaebf, before the > external variable correction. > > > > > 2014-02-01 Dirk Kirsten <dk at basex.org>: > > Hi Jean-Marc, >> >> external variables now have to be explicitly declared. You can do so by: >> >> declare variable $xml external; >> >> Cheers, >> Dirk >> >> On 01/02/14 09:16, jean-marc Mercier wrote: >> > Hi, >> > >> > I am extensively using a function wrapping xquery:eval. My use case is >> > roughly the following : >> > >> > declare function local:eval_helper($exp, >> > $args){xquery:eval('$xml'||$exp,map{'$xml' := $args})}; >> > declare variable $test := <toto><tata>1</tata></toto>; >> > local:eval_helper3('//tata', $test) >> > >> > >> > Since the following correction : [1] >> > https://github.com/BaseXdb/basex/issues/833, the previous code raises >> now a >> > [XPST0008] Undefined variable $xml. >> > >> > I have tried several combinations to find a workaround, none are >> working : >> > >> > - declare function local:eval_helper($exp, >> > $args){xquery:eval(''||$exp,map{'' := $args})}; >> > ([XPDY0050] Root of the context item must be a document node.). >> > - declare function local:eval_helper($exp, >> $args){xquery:evaluate($arg||$exp)}; >> > >> > [XPTY0019] Steps within a path expression must yield nodes; xs:integer >> > found. >> > -- declare variable $xml external := "xml", : [XPST0008] Undefined >> variable >> > $xml. >> > >> > What is the correct workaround ? >> > >> > >> > Cheers >> > >> > Jean-Marc >> > >> > >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >> >> -- >> Dirk Kirsten, BaseX GmbH, http://basex.org >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
JM
jean-marc Mercier1 Feb 2014 11:50 #
Ah....ok ! Thanks very much, it does work now. Topic closed. 2014-02-01 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 115 lines
> Hi Jean-Marc (answering on behalf of Dirk... Let's see who is faster ;), > > your query will work if you change the xquery:eval call as follows: > > xquery:eval($query || $exp,$vars) > > Best, > Christian > > > > On Sat, Feb 1, 2014 at 11:44 AM, jean-marc Mercier < > jeanmarc.mercier at gmail.com> wrote: > >> Dirkk, thx for your answer. >> >> I am really sorry, but definitively, I don't know how to use xquery:eval >> with the last release. >> >> Following your advise, I tried the following one, but it does not work: >> >> declare function local:eval_helper($exp, $args){ >> let $query := 'declare variable $xml external; $xml' >> let $vars := map { '$xml':= $args } >> return >> xquery:eval('$xml'||$exp,$vars) >> }; >> declare variable $test := <toto><tata>1</tata></toto>; >> local:eval_helper('//tata', $test) >> >> Could you try yourself ? I mean, can you make the above user case working >> ? This use case worked fineley with BaseX7.8 beta 6aeaebf, before the >> external variable correction. >> >> >> >> >> 2014-02-01 Dirk Kirsten <dk at basex.org>: >> >> Hi Jean-Marc, >>> >>> external variables now have to be explicitly declared. You can do so by: >>> >>> declare variable $xml external; >>> >>> Cheers, >>> Dirk >>> >>> On 01/02/14 09:16, jean-marc Mercier wrote: >>> > Hi, >>> > >>> > I am extensively using a function wrapping xquery:eval. My use case is >>> > roughly the following : >>> > >>> > declare function local:eval_helper($exp, >>> > $args){xquery:eval('$xml'||$exp,map{'$xml' := $args})}; >>> > declare variable $test := <toto><tata>1</tata></toto>; >>> > local:eval_helper3('//tata', $test) >>> > >>> > >>> > Since the following correction : [1] >>> > https://github.com/BaseXdb/basex/issues/833, the previous code raises >>> now a >>> > [XPST0008] Undefined variable $xml. >>> > >>> > I have tried several combinations to find a workaround, none are >>> working : >>> > >>> > - declare function local:eval_helper($exp, >>> > $args){xquery:eval(''||$exp,map{'' := $args})}; >>> > ([XPDY0050] Root of the context item must be a document node.). >>> > - declare function local:eval_helper($exp, >>> $args){xquery:evaluate($arg||$exp)}; >>> > >>> > [XPTY0019] Steps within a path expression must yield nodes; xs:integer >>> > found. >>> > -- declare variable $xml external := "xml", : [XPST0008] Undefined >>> variable >>> > $xml. >>> > >>> > What is the correct workaround ? >>> > >>> > >>> > Cheers >>> > >>> > Jean-Marc >>> > >>> > >>> > >>> > _______________________________________________ >>> > BaseX-Talk mailing list >>> > BaseX-Talk at mailman.uni-konstanz.de >>> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> > >>> >>> -- >>> Dirk Kirsten, BaseX GmbH, http://basex.org >>> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >>> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >>> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >>> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> >

⚡Generated with XQuery