<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
doctype-public="-//W3C//DTD XHTML 1.1//EN"/>
<!-- Should the doctype even exist? I doubt it -->
<!-- Convert links.html file back to xml -->
<!-- Very Minor Bug: When node in description,
     </span></li> is on new line (it should not be) -->
<!-- Later TODO: Recover attributes (Mirror, PDF, etc) -->

<xsl:template match="html">
	<xsl:apply-templates select="head"/>
	<xsl:apply-templates select="body"/>
</xsl:template>
<xsl:template match="head"/> <!-- noop -->
<!-- TODO: In future versions, pick up stylesheets -->

<xsl:template match="body">
	<links>
	<xsl:apply-templates select="h1"/>
	<xsl:apply-templates select="dl"/>
	<xsl:apply-templates select="p"/>
	</links>
</xsl:template>

<xsl:template match="h1">
 	<!-- ignore h1 tags -->
</xsl:template>
<xsl:template match="p">
	<xsl:apply-templates select="a" mode="email"/>
	<xsl:if test="contains(text(), 'ast maintained:')">
		<date><xsl:value-of select="span[@class='date']"/></date>
	</xsl:if>
</xsl:template>
<xsl:template match="a" mode="email">
	<!-- using hardcoded address instead
	<email><xsl:value-of select="substring-after(@href,':')"/></email>\
	-->
</xsl:template>

<xsl:template match="dl">
	<list>
	<xsl:attribute name="id"><xsl:value-of select="dt/@id"/></xsl:attribute>
	<!-- Getting title. text() ignores backlink, n.-s.() strips \n's -->
	<title><xsl:value-of select="normalize-space(dt/text())"/></title>
	<xsl:apply-templates select="dd"/>
	</list>
</xsl:template>

<xsl:template match="dd">
	<xsl:apply-templates select="ul/li"/>
	<xsl:apply-templates select="dl"/>
</xsl:template>

<xsl:template match="li">
	<li>
	<xsl:apply-templates select="./a" mode="site"/>
	<xsl:apply-templates select="span[@class='ltxt']"/>
	</li>
</xsl:template>

<xsl:template match="a" mode="site">
	<site><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:copy-of select="node()"/></site>
</xsl:template>

<xsl:template match="span[@class='ltxt']">
	<html><xsl:copy-of select="child::node()"/>
	<!-- TODO: Handle span[class='warn'] -->   
	</html>
</xsl:template>


</xsl:stylesheet>
