[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] implement for loop with XSLT
Dan Diebolt <dandiebolt@xxxxxxxxx> wrote on http://www.biglist.com/cgi-bin/wilma/wilma_hiliter/xsl-list/200103/msg01009.html : > I came up with the enclosed code to grab the value of > an <n> element > and generate a list of integers and their squares > between 1 and n: > > 1 1 > 2 4 > 3 9 > ... > 8 64 > 9 81 > 10 100 > > I am a bit stunned at how intricate this code looks. > Is there > a more direct way to accomplish this? try <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="UTF-8"/> <xsl:template match="/" name="square"> <xsl:param name="range" select="100"/> <xsl:param name="current" select="1"/> <xsl:value-of select="$current"/> * <xsl:value-of select="$current"/> = <xsl:value-of select="$current * $current"/> <xsl:text> </xsl:text> <xsl:if test="$current < $range"> <xsl:call-template name="square"> <xsl:with-param name="current" select="$current+1"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Tobi ===== Tobias Reif http://www.pinkjuice.com/myDigitalProfile.htm __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/?.refer=text 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
|