[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Generate N elements and attribute values

Subject: Re: Generate N elements and attribute values
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Sun, 18 Jul 2004 21:42:32 -0700 (PDT)
td name
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.