[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Generate N elements and attribute values
Hi Kenny, This is a slightly modified version of your stylesheet. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/root"> <xsl:call-template name="tr"> <xsl:with-param name="x" select="rows" /> <xsl:with-param name="y" select="cols" /> </xsl:call-template> </xsl:template> <xsl:template name="tr"> <xsl:param name="x"/> <xsl:param name="y"/> <xsl:variable name="temp" select="/root/rows" /> <tr no="{$temp - $x}"> <xsl:call-template name="td"> <xsl:with-param name="x" select="$y"/> <xsl:with-param name="y" select="$temp - $x"/> </xsl:call-template> </tr> <xsl:if test="$x > 1"> <xsl:call-template name="tr"> <xsl:with-param name="x" select="$x - 1"/> <xsl:with-param name="y" select="$y"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="td"> <xsl:param name="x"/> <xsl:param name="y"/> <td name="{$y}" /> <xsl:if test="$x > 1"> <xsl:call-template name="td"> <xsl:with-param name="x" select="$x - 1"/> <xsl:with-param name="y" select="$y"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> for e.g. when it is applied to XML - <?xml version="1.0"?> <root> <rows>4</rows> <cols>3</cols> </root> it produces output- <?xml version="1.0" encoding="UTF-8"?> <tr no="0"> <td name="0"/> <td name="0"/> <td name="0"/> </tr> <tr no="1"> <td name="1"/> <td name="1"/> <td name="1"/> </tr> <tr no="2"> <td name="2"/> <td name="2"/> <td name="2"/> </tr> <tr no="3"> <td name="3"/> <td name="3"/> <td name="3"/> </tr> Regards, Mukul > >> This is the result tree I need: > >> > >> <tr no="0"> > >> <td name="0"/> > >> <td name="0"/> > >> <td name="0"/> > >> </tr> > >> <tr no="1"> > >> <td name="1"/> > >> <td name="1"/> > >> <td name="1"/> > >> </tr> > >> <tr no="2"> > >> <td name="2"/> > >> <td name="2"/> > >> <td name="2"/> > >> </tr> > >> <tr no="3"> > >> <td name="3"/> > >> <td name="3"/> > >> <td name="3"/> > >> </tr> > >> > >> > >> Thanks, > >> Kenny Bogoe __________________________________ Do you Yahoo!? Vote for the stars of Yahoo!'s next ad campaign! http://advision.webevents.yahoo.com/yahoo/votelifeengine/
|
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
|