[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Generate N elements and attribute values


Subject: Re: [xsl] Generate N elements and attribute values
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Mon, 19 Jul 2004 01:52:06 -0700 (PDT)

Hi Kenny,
  By adding more parameters to xsl:call-template, it
should be possible to generate additional attributes
for td. For content, I think some other technique
would be required(I cannot guess just now).

But I am curious, for what purpose are you thinking to
use the generated HTML. <td name="1" a="10" b="10">
does not look like a standard HTML syntax.

Regards,
Mukul

--- "Kenny Bogoe (BogoeMD)" <kenny@xxxxxxxxx> wrote:
> 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
Keywords
xml