<?xml-stylesheet type="text/xsl" href="OrdersProducts.xsl" ?> <Orders> <Order id="1"> <Item id="1"> <Qty>10</Qty> </Item> <Item id="2"> <Qty>1</Qty> </Item> </Order> <Order id="2"> <Item id="1"> <Qty>1</Qty> </Item> </Order> <Order id="2"> <Item id="2"> <Qty>1</Qty> </Item> </Order> </Orders>--- Products ---
<Products> <Product id="1"> <Description>Produto One</Description> </Product> <Product id="2"> <Description>Produto Two</Description> </Product> </Products>Bu using the xsl:document() function we are able to reference nodes from an external XML document. The followinf XSLT document shows how we could present a report displaying the orders and related items:
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:apply-templates select="//Orders"/> </xsl:template> <xsl:template match="Order"> <b>Pedido: <xsl:value-of select="@id" /> </b> <br/> <xsl:apply-templates select="Item"/> </xsl:template> <xsl:template match="Item"> <xsl:variable name="IDProduto" select="@id" /> <xsl:value-of select="$IDProduto" /> <br/> <xsl:value-of select="document('Products.Xml')/Products/Product[@id=$IDProduto]/Description" /> <br/> </xsl:template> </xsl:stylesheet>HTH.