|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: calculating pow of numbers and a final sum
Hi Andreas,
I think that this is one of those occasions wher you do need to use recursion - I can't (at this time of morning) see any way of doing it with a simple XPath maths expression, or even XPath numeric expressions inside a loop. Try something like this - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <!-- case conversion variables --> <xsl:variable name="abc">abcdefghijklmnopqrstuvwxyz</xsl:variable> <xsl:variable name="ABC">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> <!-- kick off recursive transform --> <xsl:template match="logging"> <xsl:apply-templates select="target[1]"/> </xsl:template> <!-- simple tail-end recursive transform --> <xsl:template match="target"> <xsl:param name="base" select="1" /> public static final int <xsl:value-of select="translate(@name, $abc, $ABC)" /> = <xsl:value-of select="$base" />; <xsl:apply-templates select="following-sibling::target[1]"> <xsl:with-param name="base" select="$base * 2" /> </xsl:apply-templates> </xsl:template> </xsl:stylesheet> Using recursion to step through a sequence of elements, one by one, is in fact a helpful in many cased where you need to perform arbitrary cumulative operations which can't be done using numeric operators, sum(), position() or xsl:number, for instance in reports. Francis. -- "Never mind manoeuvre, go straight at 'em." - Admiral Horatio Nelson XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








