Skip to content

Instantly share code, notes, and snippets.

@markahesketh
Created June 21, 2012 22:21
Show Gist options
  • Save markahesketh/2968969 to your computer and use it in GitHub Desktop.
Save markahesketh/2968969 to your computer and use it in GitHub Desktop.
<data>
<products-by-instances>
<entry id="1975">
<name>Sample Name</name>
<brand>
<item id="1970">Sample Brand</item>
</brand>
<instances>
<item id="1972">MILT501</item>
<item id="1974">MILT502</item>
</instances>
</entry>
</products-by-instances>
<shopping-cart items="2" total="35">
<item id="1972" num="1" sum="5" />
<item id="1974" num="3" sum="30" />
</shopping-cart>
</data>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="products-by-instance-id" match="/data/products-by-instances/entry" use="instances/item/@id"/>
<!-- other templates redacted for brevity; the below template is being applied -->
<xsl:template match="/data/shopping-cart/item">
<xsl:value-of select="key(products-by-instance-id, @id)/brand/item"/>
<!-- desired output is "Sample Brand" -->
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment