Last month we discussed Transforming XML using XQuery updates. With XQuery 1.0 update and transform operations are rather challenging to implement. Or you can use some library to get there, like we explained in Updating XML with XQuery 1.0. In any case, we have to admit, compared to XSLT this is a shortcoming.
With the XQuery Update Facility, things will change drastically. Let's have a closer look at a concrete usage scenario from a recent question on SSDN.If preceding-sibling type="zMADDRESS", type="zZip" value should be left unchanged. Else if, preceding-sibling type="zADDRESS", type="zZip" items should be removed. And the comma and space which always seem to precede the zZip in ZAddress or zNeighb must also be removed-- if that is all within a zADDRESS. For examples: 1. Before: [cc land="xml"] 20 West Row , Canberra City, 2600[/cc] 1. After: [cc land="xml"] 20 West Row , Canberra City[/cc] 2. Before: [cc land="xml"] 82 Northbourne Ave. , Braddon , 2601[/cc] 2. After: [cc land="xml"] 82 Northbourne Ave. , Braddon[/cc] 3. Beofre: [cc land="xml"] Box 544, Burra Creek, Queanbeyan, 2620[/cc] 3. After, no change because one its preceding-siblings is "zMaddress".[/cc]
The proposed XSLT solution is as follows, [cc lang="xquery"][/cc]
What would this look like using XQuery Update Facility? [cc lang="xquery"]declare namespace tps = "http://www.typefi.com/ContentXML";copy $doc := . modify (delete node $doc//tps:c[@type='zZip'] [preceding-sibling::tps:c[@type='zAddress']], delete node $doc//tps:c[@type='zAddress'] [.=(","," ")] [following-sibling::tps:c[1][@type='zZip']]) return $doc[/cc]
I don't want to end up in one of those endless XQuery versus XSLT discussions. But beside the fact that XQuery Update Facility adds a nice palette of new functionality to XQuery, I believe it offers concise, well readable solutions.View all posts from Marc Van Cappellen on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.