Re: AW: [xsl] simple conditional looping

Subject: Re: AW: [xsl] simple conditional looping
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 16 Aug 2004 11:41:40 -0400
At 09:03 AM 8/16/2004, Keyur wrote:
my xml code is as follows:
<orders>
<order id="1">ABC</order>
<order id="2">XYZ</order>
<order id="3">QWE</order>
</orders>

The orders tag will grow as and when new orders are added. Now in my stylesheet (PRINTER FRIENDLY) I need to display the orders as below.

ORDERS:
1. ABC
2. XYZ
3. QWE
4. ________
5. ________
6. ________
.
.
.
.
50. _______

In my printer friendly stylesheet I need to display minimum 50 lines. If there are less then 50 orders then all the remaining lines will be blank with an underline. The transformed page (this xml and xsl will be transformed using ASP.NET) will be printed and the blank lines will be filled manually with a pen and Signed.

So I think conditional looping will be required.

Cleaner than the method named after me would be to process the order nodes you have, and then pass the difference between 50 and their count to a recursive template that would emit the blank lines until zero (or less than zero) was reached:


<xsl:template match="orders">
  <xsl:apply-templates select="order"/>
  <xsl:call-template name="write-blanks">
    <xsl:with-param name="counter" select="50 - count(order)"/>
  </xsl:call-template>
</xsl:template>

(Since you've already seen the recursive template I leave it to you to adjust it -- and get the numbering of the blank lines right. ;-)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread