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

Re: Constructing X number of elements

Subject: Re: Constructing X number of elements
From: Goetz Bock <bock@xxxxxxxxxxx>
Date: Tue, 21 Aug 2001 15:53:44 +0200
printstars
> How can I produce X number of elements in XSLT, where X is defined in an
> attribute of an element in the source XML file?
> [ ... ]
> I suppose I can't do this with the for-each-construct. Please help, there
> has to be a way for doing this! :)
No, this is a picture book usecase for recursively calling a named
template. Something like:

<xsl:template name="printStars">
  <!-- how many stars to print -->
  <xsl:param name="stars">0</xsl:param>
  <!-- how many start are printed already -->
  <xsl:param name="count">0</xsl:param>

  <xsl:when test="count < starts">
    <img src="starg.gif" />
    <xsl:call-template name="printStars">
      <xsl:with-param namen="start">
        <xsl:value-of select="$stars" />
      </xsl:with-param>
      <xsl:with-param name="count">
        <xsl:value-of select="$count + 1" />
      </xsl:with-param>
    </xsl:call template>
  </xsl:when>
</xsl:template>

You use it someway like:

<xsl:template match="movie">
  <div>
  <xsl:call-template name="printStars">
    <xsl:with-param name="start">
      <xsl:value-of select="@rating" />
    <xsl:with-param>
  </xsl:call-template>
  </div>
</xsl:template>

PLEASE NOTE: this is all written from memory, please use a xsl-t
             reverence to check the syntax (UNTESTED)

BTW: would someone ponate me a US powerbook g4 keyboard??? this
     german one realy su***.
-- 
Goetz Bock                                              IT Consultant
Dipl.-Inf. Univ.

Attachment: pgp00019.pgp
Description: PGP signature

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.