<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method='html' version='4.0' encoding='UTF-8' indent='yes'/>
  <xsl:template match="/">
    <html>
      <head>
        <link href="address_book_xsl.css" rel="stylesheet" type="text/css" media="screen" />
      </head>
      <body>
        <h3>Address Book</h3>
        <table border="0" cellpadding="2" cellspacing="1" width="900" align="center">
          <xsl:for-each select="address_book/record">
            <xsl:sort select="name/last"/>
            <tr valign="top">
              <th><xsl:value-of select="name/heading"/></th>
              <th><xsl:value-of select="address/heading"/></th>
              <th><xsl:value-of select="contact/heading"/></th>
              <th><xsl:value-of select="details/heading"/></th>
            </tr>
            <tr>
              <td>
                <xsl:value-of select="name/first"/><xsl:text> </xsl:text><xsl:value-of select="name/middle"/><xsl:text> </xsl:text><xsl:value-of select="name/last"/>
              </td>
              <td>
                <xsl:value-of select="address/street"/><xsl:text> </xsl:text><xsl:value-of select="address/apt"/> <br />
                <xsl:value-of select="address/city"/>,<xsl:text> </xsl:text><xsl:value-of select="address/state"/><xsl:text> </xsl:text><xsl:value-of select="address/zip"/>
              </td>
              <td>
                Work: <xsl:value-of select="contact/phone_home"/> <br />
                Cell: <xsl:value-of select="contact/phone_work"/> <br />
                Email: <xsl:apply-templates select="contact/email"/> <br />
                Website: <xsl:apply-templates select="contact/website"/>
              </td>
              <td>
                <strong>Comment</strong>:<br />
                <xsl:value-of select="details/comment"/> <br /><br />
                <strong>Relationship</strong>:<br />
                <xsl:text> </xsl:text><xsl:value-of select="details/relationship"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="email">
    <a>
      <xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute>
      <xsl:attribute name="title">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:value-of select="."/>
    </a>
  </xsl:template>
  <xsl:template match="website">
    <a>
      <xsl:attribute name="href">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="target">_blank</xsl:attribute>
      <xsl:value-of select="."/>
    </a>
  </xsl:template>
</xsl:stylesheet>

