copy attributes of one node to another

Saturday, 8 October 2016 · 3 messages · last reply 9 Oct 2016
EK
Erdal Karaca8 Oct 2016 19:28 #
Hi, I am trying to copy attributes of one node to another:
copy $x := <test a="b" c="d"></test>,
  $y := parse-xml('<o a="x" c="y"></o>')
modify (
  delete nodes $x/@*,
  insert nodes $y/@* into $x
)
return $x
Unfortunately, the resulting $x is an empty <test/> node. I expected it to have the attributes of the parsed node. Am I using parse-xml() properly? Thanks!
AB
Andy Bunce8 Oct 2016 21:36 #
Hi Erdal, parse-xml() [1] returns a document-node, you need to get the root element. Try:
copy $x := <test a="b" c="d"></test>,
  $y := parse-xml('<o a="x" c="y"></o>')
modify (
  delete nodes $x/@*,
 insert  node $y*/**/@* into $x
)
return $x
Quoted text · Erdal Karaca · 18 lines
On 8 October 2016 at 18:28, Erdal Karaca <erdal.karaca.de at gmail.com> wrote: > Hi, > I am trying to copy attributes of one node to another: > > copy $x := <test a="b" c="d"></test>, > $y := parse-xml('<o a="x" c="y"></o>') > modify ( > delete nodes $x/@*, > insert nodes $y/@* into $x > ) > return $x > > Unfortunately, the resulting $x is an empty <test/> node. I expected it to > have the attributes of the parsed node. > Am I using parse-xml() properly? > > Thanks! >
EK
Erdal Karaca9 Oct 2016 09:42 #
Thanks, Andy, that was it! 2016-10-08 21:36 GMT+02:00 Andy Bunce <bunce.andy at gmail.com>:
Quoted text · Andy Bunce · 38 lines
> Hi Erdal, > > parse-xml() [1] returns a document-node, you need to get the root element. > Try: > > copy $x := <test a="b" c="d"></test>, > $y := parse-xml('<o a="x" c="y"></o>') > modify ( > delete nodes $x/@*, > insert node $y*/**/@* into $x > ) > return $x > > /Andy > [1] https://www.w3.org/TR/xpath-functions-30/#func-parse-xml > > On 8 October 2016 at 18:28, Erdal Karaca <erdal.karaca.de at gmail.com> > wrote: > >> Hi, >> I am trying to copy attributes of one node to another: >> >> copy $x := <test a="b" c="d"></test>, >> $y := parse-xml('<o a="x" c="y"></o>') >> modify ( >> delete nodes $x/@*, >> insert nodes $y/@* into $x >> ) >> return $x >> >> Unfortunately, the resulting $x is an empty <test/> node. I expected it >> to have the attributes of the parsed node. >> Am I using parse-xml() properly? >> >> Thanks! >> > >

⚡Generated with XQuery