<?xml version="1.0" encoding='iso-8859-1'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
		xmlns:aa="urn:aaronstraupcope:xsl:functions:weblog"
                xmlns:h="http://www.w3.org/1999/xhtml"
                xmlns:x="http://www.w3.org/XML/1998/namespace"
		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
		xmlns:dc="http://purl.org/dc/elements/1.1/" 
		xmlns="http://purl.org/atom/ns#"
		xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
		exclude-result-prefixes="x aa doc"
		version = "1.0" >

<!-- ====================================================================== 

     ====================================================================== -->

     <doc:reference xmlns="">
      <referenceinfo>

       <title>atom-0.3.xsl</title>

       <abstract>
        <para />
       </abstract>

       <author>
	<surname>Cope</surname>
	<firstname>Aaron</firstname>
	<othername>Straup</othername>
       </author>

       <copyright>
	<year>2004</year>
	<holder>Aaron Straup Cope</holder>
       </copyright>

       <legalnotice>
        <para>This work is licensed under the Creative Commons
        Attribution-ShareAlike License. To view a copy of this
        license, visit http://creativecommons.org/licenses/by-sa/1.0/
        or send a letter to Creative Commons, 559 Nathan Abbott Way,
        Stanford, California 94305, USA.</para>
       </legalnotice>

       <revhistory>
        <revision>
	 <revnumber>1.0</revnumber>
	 <date>$Date: 2004/02/14 04:21:35 $</date>
	 <revremark>
	  <para>Initial release.</para>
         </revremark>
	</revision>
       </revhistory>

      </referenceinfo>

     </doc:reference>

<!-- ====================================================================== 

     ====================================================================== -->

  <xsl:output method         = "xml" />
  <xsl:output encoding       = "ISO-8859-1" />
  <xsl:output indent         = "yes" />
  <xsl:strip-space elements = "*" />

  <!-- Note use of private functions. It's my party... -->

  <xsl:template match="/">

   <feed>
    <xsl:attribute name = "version">0.3</xsl:attribute>

    <title>
     <xsl:value-of select = "aa:syn('title')" />
    </title>

    <link>
     <xsl:attribute name = "rel">alternate</xsl:attribute>
     <xsl:attribute name = "type">application/xhtml+xml</xsl:attribute>
     <xsl:attribute name = "href"><xsl:value-of select = "aa:syn('link')" /></xsl:attribute>
    </link>
    <modified>
     <xsl:value-of select = "aa:now()" />
    </modified>
    <author>
     <name>
      <xsl:value-of select = "aa:syn('creator_name')" />
     </name>
     <url>
      <xsl:value-of select = "aa:syn('creator')" />
     </url>
    </author>

    <info>
     <xsl:attribute name = "type">application/xhtml+xml</xsl:attribute>
     <xsl:attribute name = "mode">xml</xsl:attribute>
     <h:div>
      This is an Atom syndication feed. It is intended to be viewed in a news aggregator or syndicated to another site.  Please visit the <a href="http://intertwingly.net/wiki/pie/">Atom Project</a> for more information.
     </h:div>
    </info>

    <tagline>
     <xsl:attribute name = "type">text/plain</xsl:attribute>
     <xsl:value-of select = "aa:syn('description')" />
    </tagline>

    <copyright>
     <xsl:value-of select = "/h:html/h:head/h:link[@rel='dc.rights']/@href" />
    </copyright>

    <xsl:call-template name = "Entries" />
   </feed>

 </xsl:template>

 <xsl:template name = "Entries">

  <!-- I have an "index" of (n) post which is just an XHTML
       file containing a single unordered list with links.
       So, the first step is to loop over them... -->

  <xsl:for-each select = "/h:html/h:body/h:div[@id='content']/*/h:li">

  <!-- Get the permalink for each post -->

  <xsl:variable name = "permalink">
   <xsl:value-of select = "/h:html/h:head/h:base/@href" />
   <xsl:value-of select = "h:a/@href" />
  </xsl:variable>

  <!-- Then call some private functions to figure out where
       the post lives on the file system. (This is exaplained
       below.) -->

  <xsl:variable name = "htpath">
   <xsl:value-of select = "aa:htpath_for_permalink($permalink)" />
   <xsl:text>/</xsl:text>
   <xsl:value-of select = "aa:fname_default()" />
  </xsl:variable>

  <!-- Use the document() function and return a happy node
       of the post. Note that you could also just pull the 
       post down off the network. That's your business -->
       
  <xsl:variable name = "doc" select = "document($htpath)" />

  <!-- Nothing terribly exciting. All you XPath are belong to
       us and that sort of thing... -->

  <entry>

   <title><xsl:value-of select = "$doc//h:html/h:head/h:title" /></title>

    <link>
     <xsl:attribute name = "rel">alternate</xsl:attribute>
     <xsl:attribute name = "type">application/xhtml+xml</xsl:attribute>
     <xsl:attribute name = "href"><xsl:value-of select = "$permalink" /></xsl:attribute>
    </link>

    <xsl:for-each select = "$doc//h:html/h:head/h:link[@rel='weblog.link']">
    <link>
     <xsl:attribute name = "rel">
      <xsl:value-of select = "@rel" />
      <xsl:text> [</xsl:text>
      <xsl:value-of select = "position()" />
      <xsl:text>]</xsl:text>
     </xsl:attribute>
     <xsl:attribute name = "type"><xsl:value-of select = "@type" /></xsl:attribute>
     <xsl:attribute name = "href"><xsl:value-of select = "@href" /></xsl:attribute>
    </link>
    </xsl:for-each>

   <id>
    <xsl:value-of select = "$permalink" />
   </id>

   <issued>
    <xsl:value-of select = "$doc//h:html/h:head/h:meta[@name='dc.date']/@content" />
   </issued>

   <created>
    <xsl:value-of select = "$doc//h:html/h:head/h:meta[@name='dc.date.x-metadatacreated']/@content" />
   </created>

   <modified>
    <xsl:value-of select = "$doc//h:html/h:head/h:meta[@name='dc.date.x-metadatalastmodified']/@content" />
   </modified>

   <content>
    <xsl:attribute name = "type">application/xhtml+xml</xsl:attribute>
    <xsl:attribute name = "mode">xml</xsl:attribute>
    <xsl:attribute name = "xml:lang">
     <xsl:value-of select = "$doc//h:html/@x:lang" />
    </xsl:attribute>
    <xsl:copy-of select = "$doc//h:html/h:body/h:div[@id='content']/*" />
   </content>

  </entry>

  </xsl:for-each>
 </xsl:template>

<!-- ====================================================================== 
     FIN // $Id: atom-0.3.xsl,v 1.3 2004/02/14 04:21:35 asc Exp $
     ====================================================================== -->

</xsl:stylesheet>
