YAPP.xsl

darobin on 2003-04-17T10:34:16

Quite scary


it won't be truly scary...

merlyn on 2003-04-17T11:50:09

... until it evolves to the point where it can read email.

People moan at Perl's syntax, and then they embrace XSL. Go figure!

Re:it won't be truly scary...

darobin on 2003-04-17T12:31:42

Ha!

package XML::LibXSLT::Sendmail
use strict;
use XML::LibXSLT;
use Mail::Sendmail;

XML::LibXSLT->register_function( "http://example.org/mail/", "sendMail", \&xsltmail );

sub xsltmail {
  my ($to, $from, $body) = @_;
  return sendmail( To => $to, From => $from, Message => $body ); # boolean
}

...then later...

<xsl:variable name='mailOk' select='mail:sendMail( /doc/meta/author/@email, $from, ../text )'/>
<xsl:choose>
  <xsl:when test='$mailOk'>
    Mail sent.
  </xsl:when>
  <xsl:otherwise>
    Failed to send mail.
  </xsl:otherwise>
</xsl:choose>

But that was the easiest part. Now reading:

package XML::LibXSLT::Readmail
use strict;
use XML::LibXML;
use XML::LibXSLT;
use Mail::Internet;
use Mail::XML;

XML::LibXSLT->register_function( "http://example.org/mail/", "readMail", \&gotmail );

sub gotmail {
  # grab mail from account, as usual and turn into $msg Mail::Internet message
  return XML::LibXML->new->parse_string( Mail::XML->new($msg)->toXML );
}

...then later...

  <xsl:apply-templates select='mail:readMail(...params...)'/>

Scared yet, or do you want to see the MMIX implementation in XSLT? :)