Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

drefty

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

ForLoop: a simple for loop in xslt

   1  
   2  <?xml version="1.0" encoding="ISO-8859-1"?>
   3  <!--
   4  ### begin_: file metadata
   5      ### <region-file_info>
   6      ### main:
   7      ###   - name : ForLoop: a simple for loop in xslt
   8      ###     desc : |
   9      ###         Do a simple for loop in xslt displaying hello world.
  10      ###         Call this from any source xml file.
  11      ###         It works independently of the data in the xml.
  12      ###     date : created="Thu 2005-12-01 11:30:52"
  13      ###     last : lastmod="Thu 2005-12-01 11:30:57"
  14      ###     lang    : xslt
  15      ###     tags    : xml xslt loop for hello_world
  16      ### </region-file_info>
  17      -->
  18  <xsl:stylesheet version="1.0"
  19      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  20      <xsl:output method="html"/>
  21  
  22  <xsl:template match="/">
  23  
  24  <html>
  25  <head><title>Say Hello Ten Times!</title></head>
  26  <body>
  27      <b>I am going to say hello Ten Times!</b>
  28  <!-- begin_: Send_Loop_To_HTML -->
  29      <xsl:call-template name="for.loop">
  30       <xsl:with-param name="i">1</xsl:with-param>
  31       <xsl:with-param name="count">10</xsl:with-param>
  32      </xsl:call-template>
  33  </body>
  34  </html>
  35  
  36  </xsl:template>
  37  
  38  
  39  <!--begin_: Define_The_Output_Loop -->
  40    <xsl:template name="for.loop">
  41  
  42     <xsl:param name="i"      />
  43     <xsl:param name="count"  />
  44  
  45     <!--begin_: Line_by_Line_Output -->
  46     <xsl:if test="$i &lt;= $count">
  47        <br /> <b><xsl:value-of select="$i" />.</b>Hello world!
  48     </xsl:if>
  49  
  50     <!--begin_: RepeatTheLoopUntilFinished-->
  51     <xsl:if test="$i &lt;= $count">
  52        <xsl:call-template name="for.loop">
  53            <xsl:with-param name="i">
  54                <xsl:value-of select="$i + 1"/>
  55            </xsl:with-param>
  56            <xsl:with-param name="count">
  57                <xsl:value-of select="$count"/>
  58            </xsl:with-param>
  59        </xsl:call-template>
  60     </xsl:if>
  61  
  62    </xsl:template>
  63  </xsl:stylesheet>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS