See next:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='xml' omit-xml-declaration='no' encoding='utf-8' indent='yes' />
<xsl:param name='fromDate' select='20140302' />
<xsl:param name='toDate' select='20140306' />
<xsl:key name='location' match="data/row[((number(translate(@arrived, '-', '')) >= $fromDate) and (number(translate(@arrived, '-', '')) <= $toDate))]" use='@location' />
<!-- I'm lost on this one, might not even be the best way to go about it -->
<xsl:key name='won' match="data/row[@outcome='Won' and ((number(translate(@arrived, '-', '')) >= $fromDate) and (number(translate(@arrived, '-', '')) <= $toDate))]" use='@outcome' />
<xsl:template match="/*">
<locations>
<xsl:for-each select="data/row[(count(. | key('location', @location)[1]) = 1) and ((number(translate(@arrived, '-', '')) >= $fromDate) and (number(translate(@arrived, '-', '')) <= $toDate))]">
<xsl:sort select="count(key('location', @location))" order='ascending' />
<location>
<xsl:variable name="currentLocation" select="@location" />
<xsl:attribute name='name'>
<xsl:value-of select="$currentLocation" />
</xsl:attribute>
<xsl:attribute name='count'>
<xsl:value-of select="count(key('location', @location))"/>
</xsl:attribute>
<xsl:attribute name='won'>
<xsl:value-of select="count(../row[@outcome= 'Won' and @location = $currentLocation and number(translate(@arrived, '-', '')) >= $fromDate and number(translate(@arrived, '-', '')) <= $toDate])" />
</xsl:attribute>
<xsl:attribute name='lost'>
<xsl:value-of select="count(../row[@outcome= 'Lost' and @location = $currentLocation and number(translate(@arrived, '-', '')) >= $fromDate and number(translate(@arrived, '-', '')) <= $toDate])" />
</xsl:attribute>
</location>
</xsl:for-each>
</locations>
</xsl:template>
</xsl:stylesheet>
Changes:
- You can't sort on
@count
since it is in the result, NOT in the input. You need to sort on the the way youcount()
it - Added win/loss with the date range