Thursday, April 29, 2010

Set operators in XPath

What's this? A post? Fer realz? Best pretend it never happened.

Meanwhile, I'll just continue typing. About set operators in XPath, no less.

In the olden days of XPath 1.0, there was only one set operator, "|", which performed a union on node sets. So you could use an expression like "//foo | //bar" to select all foo and bar elements. If, however, you wanted the intersection or difference of two node sets, you were out of luck, as there were no dedicated operators to help you do that.

Fortunately, the much improved XPath 2.0 remedies that situation by introducing the "intersect", and "except" operators. (And "union", which is just another way of saying "|".) So now you can do "foo intersect bar" to get nodes that are both foo's and bars, and "foo except bar" to get nodes that are foo's but not bars.

Sounds great, doesn't it? Sadly, there's a big pitfall in the way that nodes are determined to be equal. You see, for purposes of these operators, nodes are only deemed equal if they are the exact same nodes, not if they merely have the same name and the same content. So, in the document below, the two foo elements are not considered equal!

<root>
<foo>This is a foo.</foo>
<foo>This is a foo.</foo>
</root>


Now what if we want to perform set operations on nodes based on equality in terms of name and content, rather than XPath's strict definition?

Fortunately, XPath does come with a function that can determine if two nodes are identical, without taking into account if they're the exact same node. We can use this to write queries that do what we want.

Let's assume we have a variable a containing the following nodes (under a nameless root, not as a sequence):

<e></e>
<f>fff</f>
<g></g>


As well as a variable b containing these nodes:

<e></e>
<f>fff</f>
<i></i>


We can now simulate "except" as follows:

$a/*[empty(for $b1 in $b/* return (if (deep-equal(.,$b1)) then (true()) else ()))]

You should read this as: for all nodes of a, return only those for which no corresponding node can be found in b.

If you understand how our "except" works, you'll have no problem understanding "intersect":

$a/*[exists(for $b1 in $b/* return (if (deep-equal(.,$b1)) then (true()) else ()))]

Read this as: for all nodes of a, return only those for which a corresponding node can be found in b.

Finally, we have "union":

$a/*[empty(for $b1 in $b/* return (if (deep-equal(.,$b1)) then (true()) else ()))],$b/*

Read this as: take a except b and add all of b. (The "except b" bit is necessary to make sure you don't get the nodes that occur in both variables twice. Without it, you'd end up with duplicate <e> and <f> elements.)

There's one thing to be aware of in these queries though. Unlike the set operators, these queries don't remove duplicates when these are already in either of the inputs. So if a contains duplicate nodes, "$a except $b" will remove these, while our query won't. Depending on your use case this is either a bug or a feature. :-)

To help you out, here's a way to remove duplicates from a. If you combine this with the queries above, you'll have something that behaves just like the set operators do. (Apart from the difference in determining when nodes are equal, of course.)

$a/*[empty(for $a1 in subsequence($a/*,1,position()-1) return (if (deep-equal(.,$a1)) then (true()) else ()))]

Read this as: go through all nodes in a and return a node only if we haven't already passed an identical one.

There ya go. Hope this'll be of some help.

84 comments:

Anonymous said...

buy tramadol online tramadol 100mg euphoria - tramadol hcl 50 mg strong

Anonymous said...

buy tramadol online tramadol 50 mg dog - tramadol 50 mg side effects for dogs

Anonymous said...

xanax order no prescription xanax dosage overdose - xanax dosage klonopin

Anonymous said...

tramadol without prescription where can i buy tramadol usa - buy tramadol online florida

Anonymous said...

buy tramadol online tramadol 650 om - tramadol no prescription mastercard

Anonymous said...

xanax online xanax dosage mayo clinic - what does a 1mg xanax look like

Anonymous said...

carisoprodol 350 mg carisoprodol glaucoma - carisoprodol zyrtec

Anonymous said...

buy tramadol online tramadol 50mg over counter - tramadol for dogs and humans the same

Anonymous said...

carisoprodol 350 mg carisoprodol over the counter - buy carisoprodol cheap

Anonymous said...

buy tramadol without a script buy tramadol online usa cheap - buy tramadol cheap online

Anonymous said...

generic xanax xanax drug long system - xanax side effects shaking

Anonymous said...

generic xanax xanax side effects nausea - question xanax 2 overdose

Anonymous said...

buy tramadol online tramadol withdrawal kratom - tramadol withdrawal rash

Anonymous said...

buy tramadol cheap online tramadol 50 mg efectos secundarios - tramadol dosage men

Anonymous said...

buy tramadol online tramadol 50 mg cheap - buy tramadol in europe

Anonymous said...

online xanax no prescription side effects of xanax 0.5mg - xanax dosage daily

Anonymous said...

buy carisoprodol online no prescription carisoprodol 350 mg controlled substance - can carisoprodol 350 mg get you high

Anonymous said...

generic xanax yellow xanax bars r039 - xanax drug test detection period

Anonymous said...

buy tramadol online buy tramadol online from usa - buy tramadol pay cod

Anonymous said...

cheap generic cialis buy brand cialis online us - cialis online usa

Anonymous said...

buy tramadol online buy tramadol online mastercard - tramadol dosage rat

Anonymous said...

cialis online buy cialis online us - buy cialis no prescription australia

Anonymous said...

cialis no prescription can i buy cialis over the counter - cialis daily work

Anonymous said...

buy tramadol online tramadol online no prescription mastercard - buy tramadol online no prescription usa

Anonymous said...

buy cialis online online apotheke cialis 20mg - review of cialis daily

Anonymous said...

buy tramadol online tramadol for dogs max dose - tramadol yellow and green capsule

Anonymous said...

buy cialis how to order cialis - generic cialis us suppliers

Anonymous said...

generic xanax xanax on employment drug test - does xanax show up same klonopin drug test

Anonymous said...

xanax online xanax and alcohol how much - xanax dosage to get you high

Anonymous said...

buy cialis super active buy cialis online with mastercard - generic cialis 20

Anonymous said...

cialis no prescription buy cialis miami - cheap genuine cialis

Anonymous said...

buy tramadol can take 2 tramadol 50 mg - tramadol withdrawal breathing

Anonymous said...

http://landvoicelearning.com/#97734 cheap tramadol without prescriptions - buytramadol-online

Anonymous said...

buy tramadol online tramadol addiction gaza - tramadol 50 mg kern pharma

Anonymous said...

generic tramadol tramadol hcl sleep - get high tramadol hcl 50mg

Anonymous said...

learn how to buy tramdadol tramadol 50 mg get high - tramadol withdrawal st john's wort

Anonymous said...

http://landvoicelearning.com/#74967 tramadol order online tramadol 50mg - usual dosage tramadol

Anonymous said...

tramadol no rx tramadol depression - tramadol hcl versus hydrocodone

Anonymous said...

http://buytramadolonlinecool.com/#30807 tramadol 50 mg how strong - tramadol 325 mg high

Anonymous said...

buy tramadol pain killer tramadol 50mg - tramadol 50mg for pets

Anonymous said...

http://blog.dawn.com/dblog/buy/#56932 cheap tramadol without prescriptions - buy online texas tramadol

Anonymous said...

http://buytramadolonlinecool.com/#30807 legit online pharmacy tramadol - can you buy tramadol in usa

Anonymous said...

buy tramadol with paypal tramadol for dogs liver - buy tramadol online no prescription needed

Anonymous said...

http://blog.dawn.com/dblog/buy/#91875 tramadol hcl usa - tramadol zyrtec interaction

Anonymous said...

http://landvoicelearning.com/#21906 taking 5 50 mg tramadol - rimadyl or tramadol for dogs

Anonymous said...

ways to buy ativan online cheap ativan online - ativan for nausea

Anonymous said...

buy tramadol buy discount tramadol - tramadol withdrawal medication

Anonymous said...

ways to buy ativan online ativan dosage in elderly - ativan side effects on children

Anonymous said...

buy ativan online ativan dosage for the elderly - where to buy ativan online

Anonymous said...

buy tramadol online tramadol online international - tramadol purchase usa

Anonymous said...

buy tramadol online tramadol dosage and side effects - tramadol for dogs and humans the same

Anonymous said...

http://ranchodelastortugas.com/#72895 xanax high forum - xanax dosage and alcohol

Anonymous said...

buy tramadol online tramadol for dogs medication - tramadol withdrawal nausea

Anonymous said...

http://staam.org/#50589 where to buy tramadol online safely - tramadol ultram wiki

Anonymous said...

http://ranchodelastortugas.com/#30416 xanax overdose many mg - blue xanax pills generic

Anonymous said...

viagra viagra prezzo italia viagra

Anonymous said...

cytotec to buy - order misoprostol cytotec - buy cytotec online malaysia

Anonymous said...

buy tramadol onlinereviews buy tramadol usa - buy tramadol cod next day delivery

Anonymous said...

order ambien from canada buy ambien mastercard - buy ambien 10mg online

Anonymous said...


http://bit.ly/11E6sdj With 24/7 call and claim centers, no matter when you need them, this company is there. Several insurance providers will offer "well being advantages" such as either primary savings or high quality reductions. They will list several different companies and the discounts they offer.

xumeiqing said...

151212meiqing
canada goose jackets
louis vuitton outlet
christian louboutin outlet
ugg boots
north face jackets
uggs on sale
uggs for sale
hollister uk
michael kors uk
timberland boots
ugg outlet
louis vuitton handbags
burberry outlet
oakley sunglasses
nike air max
michael kors outlet
polo ralph lauren
ugg outlet
true religion jeans
cheap jordans
marc jacobs
ugg australia
hollister kids
louis vuitton
christian louboutin outlet
nike air max
louis vuitton handbags
gucci handbags
coach outlet store online
oakley sunglasses
hollister clothing
ray ban outlet
michael kors outlet online
canada goose jackets
prada outlet
ray ban sunglasses outlet
jordan retro
ray-ban sunglasses
prada uk
louis vuitton outlet stores

Unknown said...

7.12lllllyuan"oakley sunglasses wholesale"
"louis vuitton handbags outlet"
"ray-ban sunglasses"
"michael kors wallet"
"ray ban sunglasses"
"oakley sunglasses wholesale"
"longchamp handbags"
"juicy couture tracksuit"
"prada sunglasses for women"
"swarovski outlet"
"ralph lauren polo"
"longchamp outlet online"
"links of london"
"cartier watches"
"nike roshe run"
"asics"
"ferragamo outlet"
"cheap ray ban sunglasses"
"polo ralph lauren"
"michael kors outlet"
"nike tn pas cher"
"ray ban sunglasses"
"tiffany and co"
"tory burch outlet online"
"michael kors outlet"
"mulberry outlet"
"tiffany jewellery"
"tory burch outlet"
"babyliss pro"
"police sunglasses for men"
"prada outlet online"
"soccer jerseys"
"michael kors clearance"
"mcm outlet"
"true religion jeans outlet"
7.12

cara menggugurkan kandungan said...

for beginners like me need a lot of reading and searching for information on various blogs. and articles that you share a very nice and inspires me

John said...

longchamp bags
christian louboutin shoes
discount oakley sunglasses
louboutin outlet
cheap air max
ralph lauren
true religion outlet online
michael kors outlet canada
longchamp handbags
yeezy boost
20170703yuanyuan

Unknown said...

uggs classic boots
nike store
ugg outlet
ugg boots
nike factory outlet
fitflops sale clearance
coach outlet
mac cosmetics
vibram fivefingers
louis vuitton
20179.25wengdongdong

Unknown said...

2017106 leilei3915

ugg boots
cheap jerseys
kate spade handbags
michael kors outlet online
michael kors handbags clearance
ralph lauren shirts
coach outlet online
prada outlet
coach outlet online
fred perry polo

Unknown said...

yeezy 700
michael kors handbags
true religion jeans
cheap nfl jerseys
golden goose francy
adidas yeezy
yeezy shoes
yeezy boost 350
kayno
fitflops sale clearance

nbde said...
This comment has been removed by the author.
nbde said...

An intricate continuous calendar replica watches likewise makes this watch an appealing alternative replica uhren for those who value finer information and have an eye for the tiniest functions on a watch. The minimalism of this watch likewise makes fake rolex it a worthwhile staple, and likewise represents that the wristwatch has the capability to go from day to night.

axing said...

Fin dalla sua istituzione, Rado si è impegnata a creare un orologio dalla bellezza duratura,rolex daytona replica che ha permesso al marchio di applicare in modo creativo materiali ceramici ad alta tecnologia all'industria orologiera,orologi replica consentendo di indossare molti polsi per tutta la vita. capolavoro.rolex replica Le ceramiche high-tech di Rado combinano un'eccellente durezza e un'eccezionale leggerezza con l'attenzione di raffinati orologiai,orologi replica offrendo sette colori affascinanti per dare a chi lo indossa un completo complemento di personalità.

axing said...

Grazie al design innovativo del marchio e al concetto di applicazione dei materiali, Rado ha lanciato l'orologio in ceramica integrale di precisione nel 1986.rolex daytona replica È la prima serie di orologi nella storia del marchio ad adottare ceramiche high-tech. L'orologio è dotato di lucidatura nera. La catena centrale di ceramiche high-tech porta un tocco di calore e giada.iwc replica Da allora, il continuo progresso della tecnologia ha creato un nuovo mondo di design di orologi in ceramica ad alta tecnologia e Rado è diventato un pioniere dei materiali e ha raggiunto l'innovazione ancora e ancora. Oggi, gli orologi in ceramica ad alta tecnologia Rado sono disponibili in eleganti stili lucidi o opachi e le combinazioni di colori si stanno espandendo: dal nero originale al bianco impeccabile,breitling replica al grigio freddo, alla lucentezza metallica scintillante. Colore, marrone cioccolato, blu notte e verde racing britannico.

replicas rolex said...

y un anillo de 60 minutos alrededor de la periferia. Sin embargo,replicas relojes las manos hacen que la "cara" de Sang Bleu se convierta en lo que es: una pesadilla para algunos, un diseño espectacular para otros. La fascinación excesiva con líneas y rombos es obvia,replicas de relojes pero encuentro algo de lógica en el caos aparentemente deliberado.

rolex replica said...

As I was handed one of the two versions of the Hublot Big Bang Sang Bleu II Chronograph,replica watches I routinely started setting its main hands to the 10:10 mark — both for photography purposes and to see what a traditionally clear-cut configuration looks like on it. I was pleased to see that the hands, when set to 10:10 line up perfectly. The stubby hour hand and the larger minute hand have their geometrics designed in a way so that they perfectly overlap,replica watches uk introducing a temporary order of relief to the dial.

replicas de relojes said...

Mint a luxusóra alapján számíthatunk, a Sang Bleu II kronográf más arcot mutat,replika órák minden apró változással a fényben vagy a csukló mozgásában. Könnyen megtartható oly módon, hogy a fő kezek fényes keretei sötétek és alig legyenek láthatóak, az óra és perc kezeknek csak a nagy, fehérre kitöltött területei maradjanak a kijelzőn. Mint ilyen, az olvashatóság valóban nem túl rossz, annyira, hogy ez bosszanthatja a dühös puristákat. Láttam,rolex replika hogy a Rolex napi adatai rosszabb olvashatósággal rendelkeznek, ezt elmondhatom neked.

fake rolex said...

A zafírkristály labdát játszik: széleihez közeli hatszögletű élek az előlap „sarkaiba” vezetnek,replika óra és ami még ennél is fontosabb, a vizuális komplexitás további elemét adják hozzá. Az olvashatóságot ezek a szempontok alig befolyásolják, bár a torony széle felé torzulást mutatnak. Amikor néhány márka esetében a „dobozkristály” a kreativitás végső és végső alkotóeleme,replika óra webáruház vagy az a tény, hogy karcálló zafírkristályt cserélnek egy karcolt mágneses plexire, ez a keverékbe dobott szokatlan kristály csemege.

nbde2020 said...

uhren replica
fake rolex uk
falsi rolex

fake uhren
fake Breitling
Breitling replica

rolex replica kaufen
fake Omega
replica orologi rolex siti sicuri

wenzi said...

The best replica watches movies are the ones that feature the timepiece in the very opening scene. Right after the Scorsese-narrated credits fade to black, cheap replica watches uk we find Felson seated at the bar of a pool hall, doing a weird sensual whiskey tasting with a female bartender. It seems, in his post-pool hustling years, he’s turned to a life of wholesale alcohol peddling.

joyshoesonline said...

Auch die leicht erhöhten Stundenindizes und die Minuten-/Sekundenspur auf dem Zifferblatt erinnern an das Retro-omega replica Speedmaster Watch Discount Forum der Vergangenheit. Das gemalte Omega-Logo ist ein weiteres Rückfallmerkmal, das mit einem etwas dünneren Gehäuse im Vergleich replica uhren deutschland zu anderen modernen Varianten gut funktioniert.

Unknown said...

j1b21k5z36 j0n72x6n25 j2n65q6p50 l6d13r9w54 n2w10d4i98 f7v79l7e88

stesyveau said...

e5j28a2x17 l7k12w8k65 u9b27c0w99 t6d66t9u42 r2e67r2r52 g4j58y9x71

Anonymous said...

Good rolex kopia post, rich in content and beautiful, very happy to share information about montre rolex replique watches with you.

Unknown said...

Cartier rolex replica uses black and red lacquers to create contrast on the dial side of the movement. The yellow gold model even features black lacquer on the case itself. The vertical edges of the case have a stunning texture, which we also find on the platinum model.

joyshoesonline said...

Die Wahl der Farbe für diese Uhr war nicht unbedingt schockierend, aber durchaus als auffällig zu bezeichnen. Bereits im Jahr 2007 veröffentlichte die beste 1: 1-Replik von Rolex die allererste GMT-Master II aus Stahl mit einer Cerachrom-Lünette. Es hatte ein schwarzes Zifferblatt, einen grünen GMT-Zeiger und eine komplett schwarze Lünette. Sogar ein Teil des Textes auf dem Zifferblatt war in einem rolex replica entsprechenden smaragdgrünen Farbton gehalten. Diese Uhr erinnerte an die alten Modelle mit komplett schwarzer Aluminiumlünette. Tatsächlich gab es einen technischen Grund dafür, dass es monochromatisch war, da gefälschte Rolex in AAA-Qualität noch nicht auf einer skalierbaren Methode gelandet war, um zweifarbige Lünetten aus Keramik herzustellen.

joyshoesshop said...

Over the next 26 years, the company began developing calibers for the wristwatch market, and in 1915 they replica watches released two caliber designs. The 75 was created without a seconds hand and the caliber 76 with a small seconds hand.
Más de una docena de expediciones a gran altitud y algunos de los mejores exploradores del mundo estaban equipados con replica relojes relojes Rolex Oyster Perpetual 1:1 mientras se aventuraban en el terreno más hostil de la Tierra.
In cambio, il marchio ha ricevuto preziosi feedback sulle prestazioni dei suoi orologi in condizioni estreme. Questo è stato rolex replica utilizzato per sviluppare orologi utensili precisi e affidabili.