xsl-list
[Top] [All Lists]

Re: AW: simple conditional looping

2004-08-16 10:12:15
I mean, i'm assuming Keyur want no more and no less than 50 lines per page, and
maybe it's not the case...

In my printer friendly stylesheet I need to display minimum 50 lines.

If there can be 50+ lines, than your solution is 100% ok...

Citando xptm(_at_)sapo(_dot_)pt:

Yes, but if you have more than 50 order, the second line of your solution
(<xsl:apply-templates select="order"/>) will give more than 50 rows on the
output, thus giving troubles...


<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>

Citando Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com>:

At 12:19 PM 8/16/2004, you wrote:
But that will have troubles is there is more than 50 order...

Not if you construct the recursive template correctly.

Passing it a negative number as a parameter (let's say you have 55 orders:
the parameter passed will be (50 - 55) = -5), you can easily "fall through"
and choose not to emit output or recurse:

<xsl:template name="write-blanks">
   <xsl:param name="counter" select="0"/>
   <xsl:if test="$counter > 0">
      ... write your blank line here ...
     <xsl:call-template name="write-blanks">
       <xsl:with-param name="counter" select="$counter - 1"/>
     </xsl:call-template>
   </xsl:if>
</xsl:template>

Cheers,
Wendell

Citando Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com>:

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. ;-)


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--









O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--









O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt