how to insert attribute?
Saturday, 12 April 2014 · 4 messages · last reply 14 Apr 2014
積J
積丹尼 Dan Jacobson12 Apr 2014 06:52 #
http://docs.basex.org/wiki/XQuery_Update mentions insert attribute. So how can I insert attribute?
$ cat x.xq
copy $c :=
<entry>
<title>Transform expression example</title>
<author>BaseX Team</author>
</entry>
modify (
replace value of node $c/author with 'BaseX',
replace value of node $c/title with concat('Copy of: ', $c/title),
insert node <author>Joey</author> into $c,
insert attribute Z {'B'} into $c/title,
)
return $c
$ basex x.xq
Stopped at /tmp/x.xq, 10/10:
[XPST0003] Expecting ')', found 'a'.$ apt-cache policy basex
basex:
Installed: 7.8.2-1
Candidate: 7.8.2-1
Version table:
*** 7.8.2-1 0
500 http://ftp.br.debian.org/debian/ unstable/main i386 Packages 100 /var/lib/dpkg/status
AG
Arve Gengelbach12 Apr 2014 12:00 #
Hi Dan,
Insert node attribute Z {'B'} into $c/title
should do it.
I recommend [XQuery Update for the impatient] as second reference for XQuery Update facility.
cheers
Arve
[XQuery Update for the impatient] http://www.xmlmind.com/tutorials/XQueryUpdate/index.html
Quoted text · 積丹尼 Dan Jacobson · 29 lines
On 12 Apr 2014, at 06:52, 積丹尼 Dan Jacobson <jidanni at jidanni.org> wrote: > http://docs.basex.org/wiki/XQuery_Update mentions insert attribute. > So how can I insert attribute? > > $ cat x.xq > copy $c := > <entry> > <title>Transform expression example</title> > <author>BaseX Team</author> > </entry> > modify ( > replace value of node $c/author with 'BaseX', > replace value of node $c/title with concat('Copy of: ', $c/title), > insert node <author>Joey</author> into $c, > insert attribute Z {'B'} into $c/title, > ) > return $c > $ basex x.xq > Stopped at /tmp/x.xq, 10/10: > [XPST0003] Expecting ')', found 'a'. > > $ apt-cache policy basex > basex: > Installed: 7.8.2-1 > Candidate: 7.8.2-1 > Version table: > *** 7.8.2-1 0 > 500 http://ftp.br.debian.org/debian/ unstable/main i386 Packages > 100 /var/lib/dpkg/status
積J
Thanks Arve, but I still have one problem. It turns out I need to do it more than once:
declare option db:parser "html";
declare option db:htmlparser "nodefaults=true";
declare option output:doctype-public "-//W3C//DTD XHTML 1.0 Transitional//EN";
declare option output:doctype-system "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
copy $c := doc("/dev/stdin")
modify (
delete nodes $c//*:span[@class="pipe"], BUT WAIT, I also want to add ALT tags to all IMG elements.
This turns out to be not a single operation.
insert node attribute alt {'BLA'} into $c//*:img
won't work. So how can I squeeze in a
for $i in $c//*:img
return insert node attribute alt {'BLA'} into $i somewhere in my otherwise working basex 7.8 program?
)
return
<html>
<head>
{$c//*:head/*:meta[@http-equiv="Content-Type"]}
{$c//*:head/*:base}
<style type="text/css">dl {{ border-bottom: thin solid;}}</style>
<title>doing - raGii</title>
</head>
<body>
{for $l in $c//*:dl return $l}
</body>
</html>AV
Arto Viitanen14 Apr 2014 07:12 #
http://docs.basex.org/wiki/XQuery_Update mentions insert attribute. So how can I insert attribute?
$ cat x.xq
copy $c :=
<entry>
<title>Transform expression example</title>
<author>BaseX Team</author>
</entry>
modify (
replace value of node $c/author with 'BaseX',
replace value of node $c/title with concat('Copy of: ', $c/title),
insert node <author>Joey</author> into $c,
insert attribute Z {'B'} into $c/title,
)
return $c
$ basex x.xq
Stopped at /tmp/x.xq, 10/10:
[XPST0003] Expecting ')', found 'a'.Attribute is node, so
insert node attribute Z {'B'} into $c/title.
On replace: replace value of node $another/@Y with 'C'.
--
Arto Viitanen
Written for BaseX 7.8. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery