<!---->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" encoding="UTF-8" />
  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="OpenContacts/Contacts/Contact">
          <table border="0" width="100%" id="table2">
            <tr>
              <td width="80%">
                <font face="Times New Roman" size="3">
                  <b>
                    <xsl:value-of select="@Name" />
                  </b>
                </font>
              </td>
              <td>
                <xsl:value-of select="@Title" />
              </td>
            </tr>
          </table>
          <div style="margin-left: 15px;">
            <font size="2" color="#800000">
              <xsl:apply-templates select="Notes" />
            </font>
          </div>
          <table border="0" width="100%" id="tablecompanies" cellspacing="0" cellpadding="0">
            <xsl:for-each select="Companies/Company">
              <tr>
                <td width="15" />
                <td width="80" bgcolor="#E0D601">
                  <font face="Times New Roman" size="2">Company: </font>
                </td>
                <td bgcolor="#FFFCBF">
                  <font size="3">
                    <a href="idlink:{@ID}">
                      <xsl:value-of select="@Name" />
                    </a>
                  </font>
                    <font size="2">  <xsl:value-of select="@Relat" /> </font>
                </td>
              </tr>
            </xsl:for-each>
          </table>
          <table border="0" width="100%" id="tableLinkedContacts" cellspacing="0" cellpadding="0">
            <xsl:for-each select="Contacts/Contact">
              <tr>
                <td width="15" />
                <td width="80" bgcolor="#6CE26C">
                  <font face="Times New Roman" size="2">Contact: </font>
                </td>
                <td bgcolor="#C7F3C7">
                  <font size="3">
                    <a href="idlink:{@ID}">
                      <xsl:value-of select="@Name" />
                    </a>
                  </font>
                    <font size="2">  <xsl:value-of select="@Relat" /> </font>
                </td>
              </tr>
            </xsl:for-each>
          </table>
          <table border="0" width="100%" id="tablecategories" cellspacing="0" cellpadding="0">
            <xsl:for-each select="Categories/Category">
              <tr>
                <td width="15" />
                <td width="80" bgcolor="#CCFF33">
                  <font face="Times New Roman" size="2">Category: </font>
                </td>
                <td bgcolor="#E4FF95">
                  <font size="3">
                    <a href="calink:{@ID}">
                      <xsl:value-of select="@Name" />
                    </a>
                  </font>
                </td>
              </tr>
            </xsl:for-each>
          </table>
          <xsl:for-each select="Sections/Section">
            <div style="margin-left: 15px;">
              <b>
                <font face="Times New Roman" size="2">
                  <xsl:value-of select="@Name" />
                </font>
              </b>
            </div>
            <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">
              <xsl:for-each select="Fields/Field">
                <tr>
                  <td width="15" />
                  <td width="80" bgcolor="#C3D9FF">
                    <font face="Times New Roman" size="2">
                      <xsl:value-of select="@Name" />:
                    </font>
                  </td>
                  <td bgcolor="#E0ECFF">
                    <font size="3">
                      <xsl:choose>
                        <xsl:when test="@Action='email'">
                          <a href="mailto:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='web'">
                          <!---->
                          <xsl:if test="starts-with(@Value, 'http://')">
                            <a href="{@Value}">
                              <xsl:value-of select="@Value" />
                            </a>
                          </xsl:if>
                          <xsl:if test="not(starts-with(@Value, 'http://'))">
                            <a href="http://{@Value}">
                              <xsl:value-of select="@Value" />
                            </a>
                          </xsl:if>
                        </xsl:when>
                        <xsl:when test="@Action='phone'">
                          <a href="tel:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='skype'">
                          <a href="skype:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='file'">
                          <a href="local:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='image'">
                          <a href="image:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='person'">
                          <a href="person:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:when test="@Action='org'">
                          <a href="org:{@Value}">
                            <xsl:value-of select="@Value" />
                          </a>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:value-of select="@Value" />
                        </xsl:otherwise>
                      </xsl:choose>
                    </font>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
            <div style="margin-left: 15px;">
              <font size="2" color="#800000">
                <xsl:apply-templates select="Notes" />
              </font>
            </div>
          </xsl:for-each>
          <p>  </p>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
  
  
  <xsl:template match="Notes">
      <xsl:call-template name="substitute">
         <xsl:with-param name="string" select="." />
      </xsl:call-template>
</xsl:template>
 <xsl:template name="substitute">
   <xsl:param name="string" />
   <xsl:param name="from" select="' '" />
   <xsl:param name="to">
      <p />
   </xsl:param>
   <xsl:choose>
      <xsl:when test="contains($string, $from)">
         <xsl:value-of select="substring-before($string, $from)" />
         <xsl:copy-of select="$to" />
         <xsl:call-template name="substitute">
            <xsl:with-param name="string" select="substring-after($string, $from)" />
            <xsl:with-param name="from" select="$from" />
            <xsl:with-param name="to" select="$to" />
         </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$string" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>                
</xsl:stylesheet>