<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/">
  <xsl:output method="xml" indent="yes"/>

  <!-- $Id: aim2foaf.xsl 57 2006-04-13 02:22:53Z dlc $ -->

  <xsl:template match="/">
    <rdf:RDF
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      xmlns:foaf="http://xmlns.com/foaf/0.1/">

    <!-- Assumes that the first item in /gaim/privacy/account
         is the "real" account -->
    <xsl:apply-templates select="/gaim/privacy/account[1]"/>

    <xsl:apply-templates select="/gaim/blist//buddy[@account = /gaim/privacy/account[1]/@name]" />
    </rdf:RDF>
  </xsl:template>

  <xsl:template match="account">
    <foaf:Person>
      <xsl:attribute name="rdf:ID">
        <xsl:value-of select="@name"/>
      </xsl:attribute>
      <xsl:for-each select="/gaim/blist//buddy[@account = /gaim/privacy/account[1]/@name]">
        <foaf:knows>
          <xsl:attribute name="rdf:nodeID">
            <xsl:value-of select="name/text()"/>
          </xsl:attribute>
        </foaf:knows>
      </xsl:for-each>
    </foaf:Person>
  </xsl:template>

  <xsl:template match="buddy">
    <foaf:Person>
      <xsl:attribute name="rdf:nodeID">
        <xsl:value-of select="name/text()"/>
      </xsl:attribute>
      <foaf:aimChatID><xsl:value-of select="name/text()" /></foaf:aimChatID>
      <xsl:choose>
        <xsl:when test="alias/text()">
          <foaf:nick><xsl:value-of select="alias/text()" /></foaf:nick>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="setting[@name='buddy_icon']/text()">
          <foaf:Image>
            <xsl:attribute name="rdf:resource">
              <xsl:text>file://</xsl:text>
              <xsl:value-of select="setting[@name='buddy_icon']/text()" />
            </xsl:attribute>
            <dc:description>
              <xsl:text>Icon of </xsl:text>
              <xsl:value-of select="name/text()"/>
              <xsl:text>.</xsl:text>
            </dc:description>
          </foaf:Image>
        </xsl:when>
      </xsl:choose>
    </foaf:Person>
  </xsl:template>

</xsl:stylesheet>
