<?xml version="1.0" ?> 

<!--
config-update.xsl - update xpath2rss configuration files

This stylesheet converts xpath2rss configuration files from the 0.6 style
to the new 0.7 style. To use it, run the stylesheet with an XSLT processor.
For example;

  % saxon old-config.xml config-update.xsl > new-config.xml

NOTE that this stylesheet DOES NOT convert the old comma-separated 
link_rm_args to space-separated arguments; you must do that manually.
-->

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:rss="http://purl.org/rss/1.0/"
  xmlns:x2r="http://www.mnot.net/xpath2rss/"
>

<xsl:strip-space elements="x2r:channels"/>

<xsl:template match="/channels">
  <x2r:channels output_base="{@dir}">
    <xsl:apply-templates mode="channel"/>
  </x2r:channels>
</xsl:template>

<xsl:template match="channel" mode="channel">
  <xsl:element name="x2r:channel">
    <xsl:if test="@id">
      <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
    </xsl:if>
    <xsl:if test="@reverse">
      <xsl:attribute name="reverse"><xsl:value-of select="@reverse"/></xsl:attribute>
    </xsl:if>
    <xsl:if test="link_rm_args">
      <xsl:attribute name="rm_args"><xsl:value-of select="link_rm_args"/></xsl:attribute>
    </xsl:if>
    <xsl:apply-templates mode="item"/>
  </xsl:element>
</xsl:template>

<xsl:template match="channellink" mode="item">
  <rss:link><xsl:value-of select='./text()'/></rss:link>
</xsl:template>

<xsl:template match="channeltitle" mode="item">
  <rss:title><xsl:value-of select='./text()'/></rss:title>
</xsl:template>

<xsl:template match="channeldescription" mode="item">
  <rss:description><xsl:value-of select='./text()'/></rss:description>
</xsl:template>

<xsl:template match="item" mode="item" xml:space="preserve"><x2r:item path="{text()}">
   <xsl:if test="../link/text()"><rss:link path="{../link/text()}"/></xsl:if>
   <xsl:if test="../title/text()"><rss:title path="{../title/text()}"/></xsl:if>
   <xsl:if test="../description/text()"><rss:description path="{../description/text()}"/></xsl:if>
  </x2r:item></xsl:template>

<xsl:template match="*" mode="item"/>

</xsl:stylesheet>
