Transforming a Dynarex document to HTML using the DxSliml gem
require 'dx_sliml'
s = <<EOF
dl
dt from:
dd $from
dt to:
dd $to
dt subject:
dd $subject
EOF
s2 =<<EOF
<?dynarex schema='email[title]/messages(from, to, subject)' delimiter='#'?>
title: Email for James
-----------------------
abc@ruby132.org # james@jamesrobertson.eu # test 123
info@gtdtoday.co.uk # james@jamesrobertson.eu # How to plan ahead (newsletter)
a123456@aol.com # info@jamesrobertson.eu # hello
EOF
d = DxSliml.new s, Dynarex.new.import(s2)
puts d.to_xslt
puts d.to_html
XSLT output:
<?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' indent='yes' omit-xml-declaration='yes'/> <xsl:template match='email'> <html> <head> <title>Email for James</title> </head> <body> <header> <xsl:apply-templates select='summary'/> </header> <main> <xsl:apply-templates select='records/messages'/> </main> </body> </html> </xsl:template> <xsl:template match='email/summary'> <dl> <xsl:for-each select='*'> <dt> <xsl:value-of select='name()'/> </dt> <dd> <xsl:value-of select='.'/> </dd> </xsl:for-each> </dl> </xsl:template> <xsl:template match='records/messages'> <dl> <dt>from:</dt> <dd><xsl:value-of select="from"/></dd> <dt>to:</dt> <dd><xsl:value-of select="to"/></dd> <dt>subject:</dt> <dd><xsl:value-of select="subject"/></dd> </dl> </xsl:template> </xsl:stylesheet>
HTML output:
<?xml version="1.0"?> <html> <head> <title>Email for James</title> </head> <body> <header> <dl> <dt>title</dt> <dd>Email for James</dd> <dt>recordx_type</dt> <dd>dynarex</dd> <dt>format_mask</dt> <dd>[!from] [!to] [!subject]</dd> <dt>schema</dt> <dd>email[title]/messages(from, to, subject)</dd> <dt>default_key</dt> <dd>from</dd> </dl> </header> <main> <dl> <dt>from:</dt> <dd>abc@ruby132.org</dd> <dt>to:</dt> <dd>james@jamesrobertson.eu test 123</dd> <dt>subject:</dt> <dd/> </dl> <dl> <dt>from:</dt> <dd>info@gtdtoday.co.uk</dd> <dt>to:</dt> <dd>james@jamesrobertson.eu</dd> <dt>subject:</dt> <dd>How to plan ahead (newsletter)</dd> </dl> <dl> <dt>from:</dt> <dd>a123456@aol.com</dd> <dt>to:</dt> <dd>info@jamesrobertson.eu</dd> <dt>subject:</dt> <dd>hello</dd> </dl> </main> </body> </html>
Resources
- dx_sliml https://rubygems.org/gems/dx_sliml
dxsliml dynarex html xslt