XQuery Update Facility versus XSLT?

XQuery Update Facility versus XSLT?

May 13, 2008 0 Comments

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"]


What would this look like using XQuery Update Facility?

[cc lang="xquery"]declare namespace tps = "";

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.

Tech Tags:

Marc Van Cappellen

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.

Comments are disabled in preview mode.