<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  exclude-result-prefixes='exsl xml'
  version="1.0">
 
  <xsl:import href='../global.xsl'/>
  <xsl:import href='../page.xsl'/> <!-- for the link-filter mode -->

  <xsl:output method='text' encoding='utf-8'/>

  <xsl:template name='message'>
  <xsl:param name='to'/>
  <xsl:param name='cc'/>
  <xsl:param name='bcc'/>
  <xsl:param name='subject'/>
  <xsl:param name='content'/>

<xsl:text
/>From: <xsl:value-of select='$config/system-email'/>
<xsl:if test='string-length( $to )'>
To: <xsl:value-of select='$to'/>
</xsl:if>
<xsl:if test='string-length( $cc )'>
CC: <xsl:value-of select='$cc'/>
</xsl:if
><xsl:if test='$bcc'>
BCC: <xsl:value-of select='$bcc'/>
</xsl:if>
Subject: [<xsl:value-of select='$site-name'/>] <xsl:value-of select='$subject'/>
<xsl:text>

</xsl:text>

<xsl:apply-templates select='exsl:node-set( $content )' mode='link-filter'/>

<xsl:call-template name='phrase'>
  <xsl:with-param name='ref'>email-footer</xsl:with-param>
</xsl:call-template>
---

All the details are on the <xsl:value-of select='$site-name-long'/> site:

<xsl:value-of select='$home-url'/>

  </xsl:template>



  <xsl:template name='format-message'>
    <xsl:param name='to'/>
    <xsl:param name='cc'/>
    <xsl:param name='subject'/>
    
    <xsl:param name='content'/>

<!-- header -->
<xsl:if test='string-length( $to )'
>To: <xsl:value-of select='$to'/>
</xsl:if>
<xsl:if test='string-length( $cc )'>
CC: <xsl:value-of select='$cc'/>
</xsl:if>
Subject: [<xsl:value-of select='$site-name'/>] <xsl:value-of select='$subject'/>
<xsl:text>

</xsl:text>

<!-- specially formatted body -->

<xsl:call-template name='format-email'>
  <xsl:with-param name='data'>

    <xsl:copy-of select='$content'/>

    <xsl:call-template name='phrase'>
      <xsl:with-param name='ref'>email-footer-html</xsl:with-param>
    </xsl:call-template>

  </xsl:with-param>    
</xsl:call-template>
---
The message was automatically generated by <xsl:value-of select='$site-name-long'/>.
<xsl:value-of select='$home-url'/>
<xsl:text>
</xsl:text>

  </xsl:template>




  <xsl:template name='format-email'>
    <xsl:param name='data'/>
    
    <xsl:apply-templates select='exsl:node-set($data)/*' mode='format'/>

  </xsl:template>


  <xsl:template mode='format' match='*'>
    <xsl:copy>
      <xsl:apply-templates mode='format'/>
    </xsl:copy>
  </xsl:template>


  <xsl:template mode='format' match='text()'>
    <xsl:value-of select='normalize-space(.)'/>
  </xsl:template>


  <xsl:template mode='format' match='br'>
    <xsl:text>^^^</xsl:text>
  </xsl:template>

  <xsl:template mode='format' match='ul/li'>
    <xsl:text>  * </xsl:text>
    <xsl:apply-templates mode='format'/>
<xsl:text>
</xsl:text>
  </xsl:template>


  <xsl:template mode='format' match='p'>
    <xsl:apply-templates mode='format'/>
<xsl:text>
</xsl:text>
  </xsl:template>

  <xsl:template mode='format' match='p[@class="indent"]'>
<xsl:text>    </xsl:text>
    <xsl:apply-templates mode='format'/>
<xsl:text>
</xsl:text>
  </xsl:template>

  <xsl:template mode='format' match='a|ul'>
    <xsl:apply-templates mode='format'/>
  </xsl:template>





</xsl:stylesheet>