1

I'm trying to update a few attributes of a SVG tag in in a Xquery function in BaseX. So far I managed to update one attribute and returning the new node but not multiple attributes.

I tried multiple updates as a variation of the statement described here but whatever I tried it wouldn't work.

declare function  page:scaleSVG ($svg as node()*, $scale as xs:integer) as  node()* {
  return // update a few values of $svg attributes and return it
};

The function above is basically what I want to achieve.

wst
  • 11,681
  • 1
  • 24
  • 39
lup3x
  • 249
  • 2
  • 9

1 Answers1

1

Use the copy/modify/return construction. Here's an example:

declare function page:scaleSVG ($svg as node()*, $scale as xs:integer) as  node()* {
copy $c := $svg
 modify (
    replace value of node $c/@width with $scale,
    replace value of node $c/@height with $scale 
 )
return $c
};

Then calling this:

page:scaleSVG(<svg width="100" height="100" />, 200)

will return this:

<svg width="200" height="200"/>
Chondrops
  • 728
  • 1
  • 4
  • 14