Article View: pl.comp.xml
Article #796Re: Looping construct in XSL? Puzzled.
From: Patryk Dwórznik
Date: Thu, 01 Feb 2001 20:43
Date: Thu, 01 Feb 2001 20:43
57 lines
2512 bytes
2512 bytes
Sue Thibodeau <smct@frontiernet.net> wrote:
> Hello,
> I am puzzled and would appreciate some help.
> I could be totally wrong, but there do not appear to be any looping
> constructs in XSL that would allow me to write "n" number of <br /> tags,
> where "n" is equal to an attribute defined in an XML file. Does anyone know
> how to do this??
> It's simple to grab the attribute value, but I can't find any mechanism to
> decrement a counter (or in any other way handle a loop). ..... I've looked
> through several books on XSL, but I'm still stuck.
> Thanks in advance for any assistance.
> Regards,
> Sue
XSL (from programming point of view) is much like functional languages
therefore the only way you can do it is to recursively call a template.
<xsl:template name="br">
<xsl:choose>
<xsl:when test="$n = 0">
<br/>
</xsl:when>
<xsl:otherwise>
<br/>
<xsl:call-template name="br">
<xsl:with-param name="n"><xsl:value-of select="$n - 1"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="somexmltag">
<xsl:call-template name="br">
<xsl:with-param name="n"><xsl:value-of select="./@someattr"/></xsl:with-param>
</xsl:call-template>
</xsl:template>
greetz,
--
dwu2iu == Patryk Dwórznik, mailto:dwuziu@3dart.com ||
mailto:dwuziu@linux.net.pl || http://www.linux.net.pl/~dwuziu/
|| ICQ #64399269 || dwu2iu@IRCNet /* GCS d- s++:+ a-- C+++$ UL++$
P+++>++++ L+++>++++ E- W++ N+ !w O- M- !V PS+ Y+ PGP- t+@ X- R
!tv b+>++ DI+ D+ G>++ e h-- r- y? */
Technical Details
Message-ID:
<95chqb$ko7$1@news.ipartners.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!warszawa.rmf.pl!news.tpi.pl!news.astercity.net!news.ipartners.pl!not-for-mailReferences:
<95bk2s$ic6$1@node17.cwnet.frontiernet.net>Show Full Headers
Complete Article Headers
From: Patryk Dwórznik <dwuziu@3dart.com>
Newsgroups: pl.comp.xml
Subject: Re: Looping construct in XSL? Puzzled.
Date: 1 Feb 2001 20:43:55 GMT
Organization: Internet Partners
Lines: 64
Message-ID: <95chqb$ko7$1@news.ipartners.pl>
References: <95bk2s$ic6$1@node17.cwnet.frontiernet.net>
NNTP-Posting-Host: sitko.3dart.com.pl
Mime-Version: 1.0
X-Trace: news.ipartners.pl 981060235 21255 195.94.211.190 (1 Feb 2001 20:43:55 GMT)
X-Complaints-To: abuse@ipartners.pl
NNTP-Posting-Date: 1 Feb 2001 20:43:55 GMT
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.14-5.0 (i686))
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!warszawa.rmf.pl!news.tpi.pl!news.astercity.net!news.ipartners.pl!not-for-mail
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit