Here is my xml
<book asin="0201100886"
created="128135928"
lastLookupTime="128135928">
<price>102.00</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<book asin="0122513363" created="128135600" lastLookupTime="128136224">
<price>50.95</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<book asin="0201441241"
created="128136896"
lastLookupTime="128136896">
<price>108.20</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<book asin="0471250600"
created="128136896"
lastLookupTime="128136896">
<price>107.95</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<book asin="0321193628"
created="128136896"
lastLookupTime="128136896">
<price>112.40</price>
</book>
I need to update all the books prices by 0.50 cents. How can I do this?
In XQuery, a recursive function is used to do the transformation.
then if the books document is referenced as $books:
Further discussion and examples are in http://en.wikibooks.org/wiki/XQuery/Typeswitch_Transformations.
Alternatively, use an XML database such as eXist-db and update insitu:
Note that XQuery update extensions are mainly implementation-dependant until XQuery Update is more widely supported
XSLT is significantly more appropriate to use than XQuery for such kind of tasks:
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
If you are looking for a solution using XQuery Update Facility: