[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [XSLT]: Recursive Function to Add/Multiply
On 10/9/06, Nuno Viana (Gmail) <nuno.carlos.viana@xxxxxxxxx> wrote:
Hi everybody, I think you are better off with two templates: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="m"> <xsl:variable name="sum"> <xsl:apply-templates select="*[1]"/> </xsl:variable> <xsl:choose> <xsl:when test="$sum != ''"> <xsl:value-of select="@value * $sum"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="@value"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="i"> <xsl:variable name="sum"> <xsl:apply-templates select="following-sibling::*[1]"/> </xsl:variable> <xsl:choose> <xsl:when test="$sum != ''"> <xsl:value-of select="@value + $sum"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="@value"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> If you are using XSLT 2.0 then you can drop the choose/when for the more terse if then else: select="if ($sum != '') then (@value + $sum) else (@value)" cheers andrew
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|