Article View: pl.comp.xml
Article #797Re: Looping construct in XSL? Puzzled.
From: Sue Thibodeau
Date: Sat, 03 Feb 2001 15:40
Date: Sat, 03 Feb 2001 15:40
70 lines
3051 bytes
3051 bytes
Patrick,
THANK YOU! :-) Your code works wonderfully! And I learned something
valuable.
Thanks again,
Sue
"Patryk Dwórznik" <dwuziu@3dart.com> wrote in message
news:95chqb$ko7$1@news.ipartners.pl...
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:
<95h8vr$rq0$1@node17.cwnet.frontiernet.net>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!warszawa.rmf.pl!news.tpi.pl!news.internetia.pl!isdnet!209.249.123.233.MISMATCH!xfer10.netnews.com!netnews.com!newspeer1.nac.net!nntp.frontiernet.net!nntp.gblx.net!news.frontiernet.net!not-for-mailReferences:
<95bk2s$ic6$1@node17.cwnet.frontiernet.net> <95chqb$ko7$1@news.ipartners.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!warszawa.rmf.pl!news.tpi.pl!news.internetia.pl!isdnet!209.249.123.233.MISMATCH!xfer10.netnews.com!netnews.com!newspeer1.nac.net!nntp.frontiernet.net!nntp.gblx.net!news.frontiernet.net!not-for-mail From: "Sue Thibodeau" <smct@frontiernet.net> Newsgroups: pl.comp.xml Subject: Re: Looping construct in XSL? Puzzled. Date: Sat, 3 Feb 2001 10:40:34 -0500 Organization: Global Crossing Telecommunications Lines: 73 Sender: UNKNOWN@209-130-221-27.nas1.roc.gblx.net Message-ID: <95h8vr$rq0$1@node17.cwnet.frontiernet.net> References: <95bk2s$ic6$1@node17.cwnet.frontiernet.net> <95chqb$ko7$1@news.ipartners.pl> NNTP-Posting-Host: 209-130-221-27.nas1.roc.gblx.net X-Trace: node17.cwnet.frontiernet.net 981215035 28480 209.130.221.27 (3 Feb 2001 15:43:55 GMT) X-Complaints-To: abuse@frontiernet.net NNTP-Posting-Date: 3 Feb 2001 15:43:55 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit