[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Increment value by group?
It looks to me as if the processing of each group is independent of the processing of any other group (because the running total starts at 1 for each group) and therefore you can use for-each-group to split the data into groups. But within each group, the processing of each item depends on the results of processing previous items, so it can't be done with a simple for-each - it needs recursion. So the structure you want is along the lines for-each-group select="job" group-adjacent="quantity" call-template name="recurse" with-param name="group" select="current-group()" with-param name="running-total" select="0" /call-template /for-each-group where the recursive named template processes the first element in the group, and then calls itself to process the remainder of the group, passing an incremented running-total as the parameter. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: watchstone@xxxxxxxxxxx [mailto:watchstone@xxxxxxxxxxx] > Sent: 20 January 2006 19:12 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Increment value by group? > > Hello: I want to process nodes based on grouping by > <quantity>. The <increment> element is used as a running > "total" based on grouping. So basically, when <quantity> is > "1", I want to process all of them as a group and use the > <increment> value to produce an output like this: > > 1/1-3 (i.e. <increment> value was "3") > 1/4-5 (i.e. <increment> value was "2" but starts where > preceding value left off) > > When <quantity> changes, I want the <increment> value to also > start over with "1". > > Can I use <xsl:for-each-group> or some such element to > accomplish this? Thanks for any tips. I'm stumped! > > <?xml version="1.0"?> > <document> > <job> > <quantity>1</quantity> > <increment>3</increment> > </job> > <job> > <quantity>1</quantity> > <increment>2</increment> > </job> > <job> > <quantity>2</quantity> > <increment>4</increment> > </job> > <job> > <quantity>2</quantity> > <increment>1</increment> > </job> > </document> > > Desired output: > <document> > <job> > <status>1/1-3</status> > </job> > <job> > <status>1/4-5</status> > </job> > <job> > <status>2/1-4</status> > </job> > <job> > <status>2/5</status> > </job>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|