1<?xml version="1.0"?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 3 <xsl:output method="xml" indent="yes"/> 4 <xsl:template match="/"> 5 <result> 6 <xsl:apply-templates/> 7 </result> 8 </xsl:template> 9 <xsl:key name="k1" match="entry" use="@cat1"/> 10 <xsl:key name="k2" match="entry" use="@cat2"/> 11 <xsl:template match="list"> 12 <xsl:variable name="k"> 13 <xsl:choose> 14 <xsl:when test="@type='one'">k1</xsl:when> 15 <xsl:otherwise>k2</xsl:otherwise> 16 </xsl:choose> 17 </xsl:variable> 18 <total> 19 <type> 20 <xsl:value-of select="@type"/> 21 </type> 22 <a> 23 <xsl:value-of select="sum( key($k,'a')/@qty )"/> 24 </a> 25 <b> 26 <xsl:value-of select="sum( key($k,'b')/@qty )"/> 27 </b> 28 </total> 29 </xsl:template> 30 <xsl:template match="entries"/> 31</xsl:stylesheet> 32