<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
encoding="utf-8"
indent="yes"/>
<!-- TODO customize transformation rules
syntax recommendation http://www.w3.org/TR/xslt
-->
<xsl:template match="/">
<html>
<head>
<title> Addressbook </title>
</head>
<body>
<div>
<h1>
Addressbook
</h1>
</div>
<div>
<strong>
Quick links to people
</strong>
</div>
<div id="quicklist">
<ul>
<xsl:apply-templates mode="quicklist"/>
</ul>
</div>
<div id="content">
<xsl:apply-templates/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="person" mode="quicklist">
<xsl:if test="@id">
<li>
<xsl:element name="a">
<xsl:attribute name="href">#<xsl:value-of select="@id"/></xsl:attribute>
<b>
<xsl:value-of select="firstname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="surname"/>
</b>
<xsl:text> (</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>)</xsl:text>
</xsl:element>
</li>
</xsl:if>
</xsl:template>
<xsl:template match="person">
<xsl:if test="@id">
<div>
<div>
<hr/>
<h2>
<xsl:element name="a">
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:value-of select="firstname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="surname"/>
</xsl:element>
</h2>
</div>
<div>
<xsl:apply-templates select="e-mail"/>
</div>
<div>
<xsl:apply-templates select="contacts"/>
</div>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="e-mail">
<xsl:if test="not(.='')">
<div>
<xsl:text>e-mail: </xsl:text>
<xsl:element name="a">
<xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="contacts">
<div>
<xsl:choose>
<xsl:when test="*">
<xsl:choose>
<xsl:when test="@visible = 'true'">
<div>
<xsl:apply-templates select="contact"/>
</div>
</xsl:when>
<xsl:otherwise>
<em>
Some contacts but not visible
</em>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<em>
No contacts
</em>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template match="contact">
<div>
<xsl:choose>
<xsl:when test="@visible='false'">
<em>
An invisible contact
</em>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="myIdVar" select="@person-ref"/>
<xsl:variable name="myPersonVar" select="/address-book/person[@id=$myIdVar]"/>
<xsl:apply-templates select="$myPersonVar" mode="list"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template match="person" mode="list">
<xsl:if test="@id">
<xsl:text>Contact: </xsl:text>
<b>
<xsl:value-of select="firstname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="surname"/>
</b>
<xsl:text> (</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>