<!-- Loop Example: Totaling a List of Numbers
     (see Michael Kay: "XSLT Programmer's Reference", page 553)
     GPL (c) Oliver Becker, 2000-07-01
     obecker@informatik.hu-berlin.de
-->
<xsl:stylesheet xmlns:loop="http://informatik.hu-berlin.de/loop" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="text" />

<xsl:template match="/">
   
<xsl:variable name="list" select="normalize-space(.)" />
   
<xsl:variable name="total" select="0" />
   
<loop:while test="contains($list,' ')">
      
<loop:last>
         
<xsl:value-of select="number($total) + number($list)" />
      
</loop:last>
      
<loop:update name="list" select="substring-after($list, ' ')" />
      
<loop:update name="total" select="number($total) + number(substring-before($list, ' '))" />
   
</loop:while>
   
<xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>