Subject: Re: [xsl] Generate N elements and attribute values From: "Kenny Bogoe (BogoeMD)" <kenny@xxxxxxxxx> Date: Mon, 19 Jul 2004 10:14:35 +0200 |
Mukul, it looks great. I guess it is possible to include one or more td attributes based on variables if I follow your example ? And content as well ? Result: <tr no="1"> <td name="1" a="10" b="10">AAA</td> <td name="1" a="15" b="20">BBB</td> </tr> <tr no="2"> <td name="2" a="25" b="10">CCC</td> <td name="2" a="15" b="15">DDD</td> </tr> Thanks a lot for your help. Kenny > 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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Generate N elements and a, Mukul Gandhi | Thread | Re: [xsl] Generate N elements and a, Mukul Gandhi |
RE: [xsl] Using XPath in an xsl:par, Michael Kay | Date | Re: [xsl] Generate N elements and a, Mukul Gandhi |
Month |