using variables along with namespace prefix
Tuesday, 5 April 2011 · 2 messages
SV
Sony Vijay5 Apr 2011 09:40 #
Hi,
I am using the sample xml document(xyz) shown below:
<entry xmlns:libx="http://libx.org/xml/libx2">
<libx:libapp> First libapp </libx:libapp>
<libx:libapp> Second libapp </libx:libapp>
</entry>I am using BaseX 6.5.2 and am trying to use a variable along with a namespace prefix in my sample xquery like so:
declare variable $libx_ns as xs:string external;
declare namespace libx=$libx_ns;
let $type := 'libapp'
return doc('xyz')/entry*[libx:{$type}]*[1]When I pass the value "http://libx.org/xml/libx2" to the parameter libx_ns and run the above xquery I see the following exception:
[XPST0003] Incomplete expression.
However, the following xquery works:
declare variable $libx_ns as xs:string external;
declare namespace libx=$libx_ns;
let $type := 'libapp'
return doc('xyz')/entry*[libx:libapp]*[1]The child nodes could be libx:libapp or libx:module etc. So, I will have to use a variable rather than hard wiring the actual child name. But, I am not sure how to use a variable along with a namespace prefix. Am I doing something wrong or is this a bug ?
Thanks,
Sony
CG
Christian Grün5 Apr 2011 09:51 #
Hi Sony,
Quoted text · Sony Vijay · 2 lines
> let $type := 'libapp' > return doc('xyz')/entry[libx:{$type}][1]
This is invalid XQuery syntax; you could try the following:
let $type := 'libapp'
return doc('xyz')/entry[name() = $type][1]The following page gives you some more alternatives:
http://www.xqueryfunctions.com/xq/c0021.html
Christian
Quoted text · Sony Vijay · 33 lines
On Tue, Apr 5, 2011 at 7:39 AM, Sony Vijay <sony.vibh at gmail.com> wrote: > Hi, > I am using the sample xml document(xyz) shown below: > <entry xmlns:libx="http://libx.org/xml/libx2"> > <libx:libapp> First libapp </libx:libapp> > <libx:libapp> Second libapp </libx:libapp> > </entry> > I am using BaseX 6.5.2 and am trying to use a variable along with a > namespace prefix in my sample xquery like so: > declare variable $libx_ns as xs:string external; > declare namespace libx=$libx_ns; > let $type := 'libapp' > return doc('xyz')/entry[libx:{$type}][1] > When I pass the value "http://libx.org/xml/libx2" to the parameter libx_ns > and run the above xquery I see the following exception: > [XPST0003] Incomplete expression. > However, the following xquery works: > declare variable $libx_ns as xs:string external; > declare namespace libx=$libx_ns; > let $type := 'libapp' > return doc('xyz')/entry[libx:libapp][1] > The child nodes could be libx:libapp or libx:module etc. So, I will have to > use a variable rather than hard wiring the actual child name. But, I am not > sure how to use a variable along with a namespace prefix. Am I doing > something wrong or is this a bug ? > Thanks, > Sony > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
Written for BaseX 6.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery