The update command
Syntax:
update expression with queryThe content of the nodes selected by the given expression is replaced by the result of evaluating the query:
-
When an element or document node is selected, the existing children are deleted, and replaced with the result of the expression.
-
When the selected element is a node kind that cannot have children, for example a comment, text node, or attribute, then its content is replaced with the string value of the query result.
Examples
Given the source document:
<cities> <city name="Berlin" country="DE"/> <city name="Munich" country="DE"/> <city name="Paris" country="FR"/> <city name="Lyon" country="FR"/> <city name="Rome" country="IT"/> </cities>The command:
update //@country[.='IT'] with "ITALIA"produces:
<cities> <city name="Berlin" country="DE"/> <city name="Munich" country="DE"/> <city name="Paris" country="FR"/> <city name="Lyon" country="FR"/> <city name="Rome" country="ITALIA"/> </cities>Given a source document:
<cities> <city><name>Berlin</name><country>DE</country></city> <city><name>Munich</name><country>DE</country></city> <city><name>Paris</name><country>FR</country></city> <city><name>Lyon</name><country>FR</country></city> <city><name>Rome</name><country>IT</country></city> </cities>The command:
update //city/name[.="Munich"] with "München"produces the document:
<cities> <city><name>Berlin</name><country>DE</country></city> <city><name>München</name><country>DE</country></city> <city><name>Paris</name><country>FR</country></city> <city><name>Lyon</name><country>FR</country></city> <city><name>Rome</name><country>IT</country></city> </cities>With the same source document, the command:
update //@country with lower-case(.)produces:
<cities> <city><name>Berlin</name><country>de</country></city> <city><name>Munich</name><country>de</country></city> <city><name>Paris</name><country>fr</country></city> <city><name>Lyon</name><country>fr</country></city> <city><name>Rome</name><country>it</country></city> </cities>