Created
December 6, 2010 15:17
-
-
Save greystate/730418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- | |
Assumes an XML document with multiple <order> elements inside a wrapping <orders> element. | |
--> | |
<!DOCTYPE xsl:stylesheet [ | |
<!-- Close your eyes and take a leap of faith! --> | |
<!ENTITY countAllOccurences "sum(ancestor::orders/order/orderLine[properties/productNumber = current()/following-sibling::productNumber]/@quantity)"> | |
]> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
> | |
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> | |
<!-- Find orderLine elements by the productNumber they contain --> | |
<xsl:key name="orderLine-by-productNumber" match="orderLine" use="properties/productNumber" /> | |
<xsl:template match="orders"> | |
<ol> | |
<xsl:apply-templates select="order/orderLine[count(. | key('orderLine-by-productNumber', properties/productNumber)[1]) = 1]/properties/productName"> | |
<xsl:sort select="&countAllOccurences;" data-type="number" order="descending" /> | |
</xsl:apply-templates> | |
</ol> | |
</xsl:template> | |
<xsl:template match="productName"> | |
<li> | |
<xsl:value-of select="." /> (<xsl:text /> | |
<xsl:value-of select="&countAllOccurences;" />)<xsl:text /> | |
</li> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment