Using the Rx_sliml gem to create an XML stylesheet from a RecordX object
require 'rx_sliml'
require 'dynarex'
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
dx = Dynarex.new.import(s2)
r = RxSliml.new(s, dx.all[2]).to_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='kvx'> <html> <head> <title> <xsl:value-of select='summary/title'/> </title> </head> <body> <header> <xsl:apply-templates select='summary'/> </header> <main> <xsl:apply-templates select='body'/> </main> </body> </html> </xsl:template> <xsl:template match='kvx/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='body'> <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>
Resources
- rx_sliml https://rubygems.org/gems/rx_sliml
rx_sliml kvx recordx xslt