[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Alternatives to "Stopping" a for-each

Subject: Re: Alternatives to "Stopping" a for-each
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 14 Feb 2013 13:43:55 +0000
Re:  Alternatives to "Stopping" a for-each
Don't think of a for-each as a loop. Think of it as a functional mapping operation, where you apply a function (the body of the for-each) to every item in a sequence - quite possibly in parallel. There's no concept that the system doesn't start processing the second item until it has finished processing the first.

Your alternatives are

(a) decide up-front which items in the sequence to process, and select them in the select expression of the for-each

(b) if you need to make a dynamic decision, replace the for-each with a recursion.

(c) or in XSLT 3.0, xsl:iterate gives you a "sequential" equivalent of for-each where the way each item is processed can depend on the results of processing previous items (and an xsl:break that terminates processing)

Michael Kay
Saxonica

On 14/02/2013 13:10, trond.huso@xxxxxx wrote:
I have to create the following list based on xml-structure below. It is a list of ranked horses, and where the last number (if there are more than one number) is the winning horse.

Rangering: 1. avd: 7-11-6-12 (str. 4), 2. avd: 9 (str. 1), 3. avd: 8, 4. avd: 4-8 (str. 5), 5. avd: 6 (str. 10).

The example uses the bold part of the text.

So the idea is that I am sorting the ranking, looping the structure. When I hit the winning horse, I shall stop the loop.
Now I know that you cannot stop a for-each in xslt, so what is the best way to this then?



<Start>
                             <StartNo>1</StartNo>
                             <Horse>
                                 <RegNo>N-04-0514</RegNo>
                                 <Name>Rise Stjerna</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>8279</LicenseNo>
                                 <FirstName>Kristine</FirstName>
                                 <LastName>Kvasnes</LastName>
                             </Driver>
                             <Distance>2140</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>9</Ranking>
                         </Start>
                         <Start>
                             <StartNo>2</StartNo>
                             <Horse>
                                 <RegNo>N-07-0133</RegNo>
                                 <Name>Bovis Rambo</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>79</LicenseNo>
                                 <FirstName>Thor</FirstName>
                                 <LastName>Borg</LastName>
                             </Driver>
                             <Distance>2140</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>6</Ranking>
                         </Start>
                         <Start>
                             <StartNo>3</StartNo>
                             <Horse>
                                 <RegNo>N-02-0165 </RegNo>
                                 <Name>Cdne Kongen</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>2014063</LicenseNo>
                                 <FirstName>Oda</FirstName>
                                 <LastName>Verdal</LastName>
                             </Driver>
                             <Distance>2140</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>11</Ranking>
                         </Start>
                         <Start>
                             <StartNo>4</StartNo>
                             <Horse>
                                 <RegNo>S-08-0191</RegNo>
                                 <Name>JC&rvsC8 Kristina</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>17044</LicenseNo>
                                 <FirstName>Cystein</FirstName>
                                 <LastName>Tjomsland</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>true</Scratched>
                             <Ranking>0</Ranking>
                         </Start>
                         <Start>
                             <StartNo>5</StartNo>
                             <Horse>
                                 <RegNo>N-07-0107</RegNo>
                                 <Name>Magnums Amadeus</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>5697</LicenseNo>
                                 <FirstName>Arild</FirstName>
                                 <LastName>BerC%s</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>5</Ranking>
                         </Start>
                         <Start>
                             <StartNo>6</StartNo>
                             <Horse>
                                 <RegNo>578001020080549</RegNo>
                                 <Name>Willblesen</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>30399</LicenseNo>
                                 <FirstName>Rudolf</FirstName>
                                 <LastName>Roland</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>3</Ranking>
                         </Start>
                         <Start>
                             <StartNo>7</StartNo>
                             <Horse>
                                 <RegNo>N-05-0660</RegNo>
                                 <Name>Lill Ronja</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>1537</LicenseNo>
                                 <FirstName>Eirik</FirstName>
                                 <LastName>HC8itomt</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>1</Ranking>
                         </Start>
                         <Start>
                             <StartNo>8</StartNo>
                             <Horse>
                                 <RegNo>N-04-0365</RegNo>
                                 <Name>Per Even</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>65285</LicenseNo>
                                 <FirstName>Vidar</FirstName>
                                 <LastName>Tjomsland</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>7</Ranking>
                         </Start>
                         <Start>
                             <StartNo>9</StartNo>
                             <Horse>
                                 <RegNo>N-05-0179</RegNo>
                                 <Name>Cs Glimten</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>5040</LicenseNo>
                                 <FirstName>Johan HerbjC8rn</FirstName>
                                 <LastName>Undem</LastName>
                             </Driver>
                             <Distance>2160</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>10</Ranking>
                         </Start>
                         <Start>
                             <StartNo>10</StartNo>
                             <Horse>
                                 <RegNo>N-06-0047</RegNo>
                                 <Name>Pola Linus</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>2127</LicenseNo>
                                 <FirstName>Kristian</FirstName>
                                 <LastName>Malmin</LastName>
                             </Driver>
                             <Distance>2180</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>8</Ranking>
                         </Start>
                         <Start>
                             <StartNo>11</StartNo>
                             <Horse>
                                 <RegNo>N-03-0261</RegNo>
                                 <Name>Odintroll</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>8345</LicenseNo>
                                 <FirstName>Ole Johan</FirstName>
                                 <LastName>Cstre</LastName>
                             </Driver>
                             <Distance>2180</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>2</Ranking>
                         </Start>
                         <Start>
                             <StartNo>12</StartNo>
                             <Horse>
                                 <RegNo>N-07-0209</RegNo>
                                 <Name>Tallas</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>5740</LicenseNo>
                                 <FirstName>Jan Rune</FirstName>
                                 <LastName>Gaustad</LastName>
                             </Driver>
                             <Distance>2180</Distance>
                             <Scratched>false</Scratched>
                             <Ranking>4</Ranking>
                         </Start>


Best regards,


Trond HusC8
System Developer
www.ntb.no

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.