<?xml version="1.0"?>

<!-- Loop Example: Finding the Total Sales Value
     (see Michael Kay: "XSLT Programmer's Reference", page 555)
     GPL (c) Oliver Becker, 2000-07-01
     obecker@informatik.hu-berlin.de
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:loop="http://informatik.hu-berlin.de/loop">

<xsl:output method="text" />

<xsl:template match="/">
   <xsl:variable name="list" select="//book" />
   <xsl:variable name="total" select="0" />
   <loop:while test="$list">
      <xsl:variable name="first" select="$list[1]" />
      <loop:last>
         <xsl:text>Total sales value is: </xsl:text>
         <xsl:value-of select="format-number($total,'$#.00')" />
         <xsl:text>&#xA;</xsl:text>
      </loop:last>
      <loop:update name="list" select="$list[position()!=1]" />
      <loop:update name="total" 
                   select="$first/sales * $first/price + $total" />
   </loop:while>
</xsl:template>

</xsl:stylesheet>
