Re: [xsl] Constructing X number of elements

Subject: Re: [xsl] Constructing X number of elements
From: Goetz Bock <bock@xxxxxxxxxxx>
Date: Tue, 21 Aug 2001 15:53:44 +0200
> 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