xsl-list
[Top] [All Lists]

Re: [xsl] Alternatives to "Stopping" a for-each

2013-02-14 07:44:09
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(_dot_)huso(_at_)ntb(_dot_)no 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>Ådne 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>Jærvsø Kristina</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>17044</LicenseNo>
                                 <FirstName>Øystein</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>Berå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>Høitomt</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>Ås Glimten</Name>
                             </Horse>
                             <Driver>
                                 <LicenseNo>5040</LicenseNo>
                                 <FirstName>Johan Herbjørn</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>Østre</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 Husø
System Developer
www.ntb.no




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




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

<Prev in Thread] Current Thread [Next in Thread>