Puna

Login
  • Home
  • Archives
  • Bookmarks

    Entertainment

    • Hoyts, Riccarton
    • Hoyts, Regent
    • Reading, Palms
    • Snackfood Marauders
    • Sky TV

    Friends

    • No Right turn
    • Jon Taplin

    Utilities

    • Email anonymizer
    • Free software

    Goods

    • Laptops

    Reference

    • New Zealand
    • Christchurch
    • White pages
    • Christchurch Street Maps
    • Night sky
    • Logical fallacies
    • Weather
  • Contact
  • Contents
  • Photos
  • Travels

This...

<records>
	<contact id="0001">
		<title>Mr</title>
		<forename>John</forename>
		<surname>Smith</surname>
	</contact>
	<contact id="0002">
		<title>Dr</title>
		<forename>Amy</forename>
		<surname>Jones</surname>
	</contact>
	...
</records>

to this...

Jones,
Amy (Dr)
Brian (Mr)
Smith,
Fiona (Ms)
John (Mr)

use this...

<xsl:key name="contacts-by-surname" match="contact" use="surname" />
<xsl:template match="records">
	<xsl:for-each select="contact[count(. | key('contacts-by-surname', surname)[1]) = 1]">
		<xsl:sort select="surname" />
		<xsl:value-of select="surname" />,<br />
		<xsl:for-each select="key('contacts-by-surname', surname)">
			<xsl:sort select="forename" />
			<xsl:value-of select="forename" /> (<xsl:value-of select="title" />)<br />
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>