Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: xsl totals composed from variables [Thread Next] Re: xsl totals composed from variablesTo: NULL Date: 11/3/2006 10:33:00 PM
For example:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:key name="comp" match="item" use="name" />
<xsl:template match="/">
<table border="1">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="item">
<tr><td><xsl:value-of select="name" /> </td>
<td><xsl:value-of select="price" /></td>
<xsl:for-each select="component">
<td><xsl:value-of select="cname" /></td>
<td><xsl:value-of select="quantity" /></td>
<xsl:variable name="cn" select="cname" />
<xsl:variable name="q" select="quantity" />
<xsl:for-each select="key('comp', $cn)">
<xsl:variable name="p" select="price*$q" />
<td><xsl:value-of select="$p"/></td>
---------------------------
Test (must be within scope of the $p variable):
<xsl:call-template name="loop">
<xsl:with-param name="pr" select="$p"/>
</xsl:call-template>
---------------------------
</xsl:for-each>
<!-- <xsl:value-of select="quantity" /> -->
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="pr"/>
<xsl:param name="t" select="0"/>
<xsl:message>pr=<xsl:value-of select="$pr"/>, t=<xsl:value-of
select="$t"/></xsl:message>
<xsl:choose>
<xsl:when test="$pr">
<xsl:call-template name="loop">
<xsl:with-param name="t" select="$pr+$t"/>
<!-- I presume you meant to add: -->
<xsl:with-param name="pr" select="$pr -1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$t" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
