trying to rename all node elements from <foo/> to <bar/>
Friday, 19 June 2020 · 3 messages · last reply 21 Jun 2020
N
Nicholas19 Jun 2020 02:15 #
Hi,
How do I rename all the "record" nodes in a database? I'm trying:
for $x in db:open("bccdc_covid19")return return rename node $x//record as "baz"
but this gives back
Stopped at ., 1/13:
[XPDY0002] bc.rename.xq: no context value bound.
or
[XPST0003] Unexpected end of query: 'rename node $x/...'.
depending whether it's run from within the basex console.
thanks,
Nick
N
Nicholas19 Jun 2020 02:22 #
Pardon, this indeed works:
for $x in db:open("bccdc_covid19")return rename node $x//baz as "foo"
but only for the first node baz -- how can I rename all of the nodes? Or match an Xpath?
It's CSV data, so the general layout (?) is csv/record/entry and instead of "record" I'd want that to be something else -- doesn't really matter what.
CG
Christian Grün21 Jun 2020 12:54 #
Hi Nick,
Quoted text · Nicholas · 2 lines
> for $x in db:open("bccdc_covid19") > return rename node $x//baz as "foo"
The rename expression must be performed on a single target node. Try this instead:
for $baz in db:open("bccdc_covid19")//baz
return rename node $baz as "foo"…or…
db:open("bccdc_covid19")//baz ! (rename node . as "foo")Hope this helps,
Christian
Quoted text · Nicholas · 17 lines
On Fri, Jun 19, 2020 at 12:22 AM Nicholas <saunders.nicholas at gmail.com> wrote: > > Pardon, this indeed works: > > > for $x in db:open("bccdc_covid19") > return rename node $x//baz as "foo" > > > but only for the first node baz -- how can I rename all of the nodes? > Or match an Xpath? > > > It's CSV data, so the general layout (?) is csv/record/entry and instead > of "record" I'd want that to be something else -- doesn't really matter > what. >
Written for BaseX 9.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery