Subject: Re: AW: [xsl] simple conditional looping From: xptm@xxxxxxx Date: Mon, 16 Aug 2004 18:06:03 +0100 |
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@xxxxxxxxxxxxxxxx>: > 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@xxxxxxxxxxxxxxxx>: > > > > > 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@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 > ====================================================================== > > O SAPO ja esta livre de vmrus com a Panda Software, fique vocj tambim! Clique em: http://antivirus.sapo.pt
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: AW: [xsl] simple conditional lo, Wendell Piez | Thread | Re: AW: [xsl] simple conditional lo, xptm |
RE: [xsl] Passing parameter into xs, cknell | Date | Re: AW: [xsl] simple conditional lo, xptm |
Month |