Subject: RE: RE: [xsl] Incrementing number in a for loop ?? From: cknell@xxxxxxxxxx Date: Thu, 31 Jul 2003 10:43:14 -0400 |
Ask yourself, how can I determine from the XML how many quotes I need to output. Let me explain. Two nights ago I was working with my wife on a project she is doing. She wanted to indent the HTML output based on the nested depth of an element in the XML input. I showed her how she could use the count() function in conjunction with an XPath that selected all ancestor nodes with a particular name to determine how much to indent the output. So, with an XML structure like this: <item> <item> <item></item> </item> </item> you could set up a template like this: (I don't have the code with me, so I rely on the other list readers to correct errors and omissions) <xsl:template match="item"> <div style="position:relative;left:{count(ancestor::*[name()='item'])*10}px;"><div> </xsl:template> Each time the processor encountered an "item" element, it would determine the number of ancestor "item" elements, multiply that number by the constant "10", and indent the output by the product number of pixels. In your situation, a simple multiplication won't do what you need, but the principle applies. How many different-length strings of quotation marks might you need? -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx> Sent: Thu, 31 Jul 2003 09:44:29 -0400 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Incrementing number in a for loop ?? hi, First of all thanks a mile for answering my query which confirmed my guess that i can not increment variable in xsl. Well my xsl is like this. When i m parsing my xsl file i m creating quotes like this and it is HARDCODED and this I counted and put into my xsl file as show below where at someplace i need like this. <xsl:text> ``````````````````````````````</xsl:text> And at other place i need something like this. <xsl:text> ``````</xsl:text> So i was trying to confirm that can i declare a variable and code in other languages as under: -------------------------------------------------------------------- int quoteCount = 30; // for example this many quotes i need for(int i = 0; i < quoteCount ; i++) printf("`"); // cout << "`" \ // Console.Write("`") // System.Out.print("`"); --------------------------------------------------------------------- Thanks for taking out your time and answering my question. Well i thought from here i will get conformace for my guessing thats why i asked question like this and if it bothered someone i am really sorry for that. Regards, Dipesh > >Date: Wed, 30 Jul 2003 21:27:00 -0400 >From: cknell@xxxxxxxxxx >Subject: RE: [xsl] Incrementing number in a for loop ?? > >Variables, once declared, cannot be changed. You could pass the old value to the called template with a parameter and declare a variable inside the template which adds one to the value passed as a parameter when the template is called recursively, but probably there's a better way to achieve the result. We could tell more if you supply a stripped-down example of your source XML and your stylesheet. >- -- >Charles Knell >cknell@xxxxxxxxxx - email > > > >- -----Original Message----- >From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx> >Sent: Wed, 30 Jul 2003 19:56:22 -0400 >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >Subject: [xsl] Incrementing number in a for loop ?? > >Hi, > >I am creating a text output from xml and at some places i have to give >hardcoded special characters. > >Is is possible to declare a variable having numerical value and incrementing >it using expression inside for loop ? > >If somebody can throw some light on this issue i would be grateful. > >Regards, >Dipesh > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > >------------------------------ > >Date: Wed, 30 Jul 2003 21:27:18 -0400 >From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> >Subject: Re: [xsl] Incrementing number in a for loop ?? > >At 2003-07-30 19:56 -0400, Dipesh Khakhkhar wrote: >>I am creating a text output from xml and at some places i have to give >>hardcoded special characters. > >This not a very explicit description of a problem that needs to be solved >using incrementing variables. > >>Is is possible to declare a variable having numerical value and incrementing >>it using expression inside for loop ? > >No ... this is a FFFFAQ ... even a simple query will tell you the answer to >this question: > > http://www.google.com/search?as_q=increment+global+variable+xslt > >Gee, it even happens to be my answer that is at the top of the list tonight. > >>If somebody can throw some light on this issue i would be grateful. > >Variables in XSLT do not vary within their scope. Now your question has >been answered, but you only asked a yes/no question and you haven't given >enough detail for anyone to help you with your real problem. > >If you take a moment to describe the nature of the problem you are trying >to solve where you think you need a varying variable, people on the list >will be able to tell you about the position() function or the <xsl:number/> >instruction, or about tree walking with recursive template calls, or any of >a number of other XSLT facilities that may be able to help you solve your >problem. > >And please take your time to try and do *some* research before asking >people to take from their time to answer your questions that have already >been answered. > >I hope this helps. > >............... Ken > > >- -- >Upcoming hands-on courses: in-house corporate training available; >North America public: XSL-FO Aug 4,2003; XSLT/XPath Aug 12, 2003 > >G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx >Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ >Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) >ISBN 0-13-065196-6 Definitive XSLT and XPath >ISBN 0-13-140374-5 Definitive XSL-FO >ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath >ISBN 1-894049-11-X Practical Formatting Using XSL-FO >Member of the XML Guild of Practitioners: http://XMLGuild.info >Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > >------------------------------ > >Date: Wed, 30 Jul 2003 18:39:35 -0700 (PDT) >From: Mukul Gandhi <mukulw3@xxxxxxxxx> >Subject: Re: [xsl] Incrementing number in a for loop ?? > >You *cannot increment* variables in XSLT. But you may >use count() and possibly other workarounds to generate >serial nos. > >Regards, >Mukul > >> Is is possible to declare a variable having >> numerical value and incrementing >> it using expression inside for loop ? >> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Thread | RE: RE: [xsl] Incrementing number i, Dipesh Khakhkhar | |
Date | RE: [xsl] FW: How to store a node i, ohmson ampere | |
Month |