<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tb="http://eastgate.com/Tinderbox/maparent"
  xmlns:rpc="http://maparent.webhop.net/xmlrpc"
	extension-element-prefixes="tb rpc"
  version="1.0">

  <xsl:param name="callingNode"/>

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:template match="/">
		<text>
			<tb:declareStyleChange/>
			<xsl:apply-templates/>
		</text>
	</xsl:template>

  <xsl:template match="head"/>
  <xsl:template match="style"/>

  <xsl:template match="p">
    <xsl:apply-templates/>	
		<xsl:text>
</xsl:text>
	</xsl:template>

  <xsl:template match="a[@href]">
    <xsl:variable name="anchorId" select="generate-id(.)"/>
    <tb:declareNewLink name="'href'" sourceid="rpc:callingNode()" startId="$anchorId" url="@href"/>
    <xsl:apply-templates/>
    <tb:endNewLink id="$anchorId"/>
  </xsl:template>

  <xsl:template match="b">
		<tb:declareStyleChange bold="1"/>
    <xsl:apply-templates/>
		<tb:declareStyleChange bold="0"/>
  </xsl:template>

  <xsl:template match="i">
		<tb:declareStyleChange italic="1"/>
    <xsl:apply-templates/>
		<tb:declareStyleChange italic="0"/>
  </xsl:template>

	<xsl:template match="text()">
		<xsl:if test="normalize-space(.) != ''">
			<xsl:copy/>
		</xsl:if>
	</xsl:template>

  <xsl:template match="*">
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>
