O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Joins

Problem

You want to relate elements in a document to other elements in the same or different document.

Solution

A join is the process of considering all pairs of element as being related (i.e., a Cartesian product) and keeping only those pairs that meet the join relationship (usually equality).

To demonstrate, I have adapted the supplier parts database found in Date’s An Introduction to Database Systems (Addison Wesley, 1986) to XML:

<database> <suppliers> <supplier id="S1" name="Smith" status="20" city="London"/> <supplier id="S2" name="Jones" status="10" city="Paris"/> <supplier id="S3" name="Blake" status="30" city="Paris"/> <supplier id="S4" name="Clark" status="20" city="London"/> <supplier id="S5" name="Adams" status="30" city="Athens"/> </suppliers> <parts> <part id="P1" name="Nut" color="Red" weight="12" city="London"/> <part id="P2" name="Bult" color="Green" weight="17" city="Paris"/> <part id="P3" name="Screw" color="Blue" weight="17" city="Rome"/> <part id="P4" name="Screw" color="Red" weight="14" city="London"/> <part id="P5" name="Cam" color="Blue" weight="12" city="Paris"/> <part id="P6" name="Cog" color="Red" weight="19" city="London"/> </parts> <inventory> <invrec sid="S1" pid="P1" qty="300"/> <invrec sid="S1" pid="P2" qty="200"/> <invrec sid="S1" pid="P3" qty="400"/> <invrec sid="S1" pid="P4" qty="200"/> <invrec sid="S1" pid="P5" qty="100"/> <invrec sid="S1" pid="P6" qty="100"/> <invrec sid="S2" pid="P1" qty="300"/> <invrec sid="S2" pid="P2" qty="400"/> <invrec ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required