<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                version="2.0">
<xsl:output method="html" indent="yes"/>
 <xsl:template match="ebay">
  <html><body><table>
    <xsl:apply-templates
      select="category[not (@subcategory-of)]"/>
   </table></body></html>
 </xsl:template>

 <xsl:template match="category">
  <tr>
   <td>
    <table>
     <tr>
      <td colspan="3" align="center">
       <xsl:value-of select="@name"/>
      </td>
     </tr>
     <!-- all subcategories -->
     <xsl:apply-templates select="id(@has-subcategory)"/>
     <!-- all auctions of that category -->
     <xsl:variable name="cat" select="string(@name)"/>
     <xsl:apply-templates
          select="//auction[object/id(@category)/string(@name)=$cat]">
       <xsl:sort select="fn:max(bid/number(@price))"
                 data-type="number" order ="ascending"/>
     </xsl:apply-templates>
    </table>
   </td>
  </tr>
 </xsl:template>

 <xsl:template match="auction">
  <tr>
   <td>
    <xsl:value-of select="object/type"/>
   </td>
   <!-- alternatively, one of the following can be used -->
   <td>
    <xsl:value-of select="bid[position()=last()]/@price"/>
   </td>
   <td>
    <xsl:value-of select="bid[@price = fn:max(../bid/@price)]/@price"/>
   </td>
   <td>
    <xsl:value-of select="@end"/>
   </td>
  </tr>
 </xsl:template>
</xsl:stylesheet>
