﻿<?xml version="1.0" encoding="UTF-8"?>
<!--Convert XML of Open Contacts' export into an intermedia XML with contact names, each of which has
1 URL link, and a list of XFN friendship tags which are mapped from categories.
You may need to modify the mappings from OC categories to XFN relationships 
according to your own management of categories while using Open Contacts.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" />

  <xsl:template match="/">
    <Contacts>

      <xsl:for-each select="OpenContacts/Contacts/Contact">

        <Contact>
          <Name>
            <xsl:value-of select="@Name"/>
          </Name>
          <URL>
            <xsl:value-of select="Sections/Section[contains(@Name, 'Personal')]/Fields/Field[contains(@Name, 'Blog')]/@Value"/>
          </URL>
          <Rel>
            <xsl:apply-templates select="Categories"/>
          </Rel>
        </Contact>

      </xsl:for-each>
    </Contacts>
  </xsl:template>

  <xsl:template match="Categories">
    <xsl:for-each select="Category">
      <xsl:choose>
        <!--Map from OC's category to XFN friendship -->
        <xsl:when test="@Name='Friends'">friend</xsl:when>
        <!--Map from similar OC's categories to XFN friendship-->
        <xsl:when test="contains(@Name, 'Business')">contact</xsl:when>
        <!--Map from other OC categories-->
        <xsl:otherwise>met</xsl:otherwise>
      </xsl:choose>
      <xsl:text> </xsl:text>
    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>
