If you want to output this XML as a ranking? The usual answer for this sort of thing in XSLT 1.0 is Muenchian grouping. First define a key.
1 | <xsl:key name="bookingsBySource" match="booking" use="source" /> |
Then use the following trick to iterate over the unique source values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <xsl:template match="/bookings"> <ol> <xsl:for-each select="booking[generate-id() = generate-id(key('bookingsBySource', source)[1])]"> <!-- sort by number of bookings, largest first --> <xsl:sort select="count(key('bookingsBySource', source))" data-type="number" order="descending" /> <li> <xsl:value-of select="source"/> <xsl:text>: </xsl:text> <xsl:value-of select="count(key('bookingsBySource', source))" /> <xsl:text> booking(s)</xsl:text> </li> </xsl:for-each> </ol> </xsl:template> |
The for-each select pulls out only the first booking element for each source value.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.