Merge entry- or template-based XML with XSL templates.
We’ve done quite a bit of work with XML stored in ExpressionEngine entries and XSL stored in server files, using in-template PHP to merge the two together. What’s the natural progression? Tag-based transforms with XSL stored in EE templates.
Download for ExpressionEngine 2 Download for ExpressionEngine 1.6.9To install (EE2):
To install (EE 1.6.9):
Usage is simple. My XSL is in template index in template group xslt.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="/">
Hello <xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
In my site’s template, I use the xsltransform tag to pull XML from an entry together with that template.
{exp:weblog:entries weblog="xml" url_title="xml1"}
{exp:xsltransform xsl='xslt/index'}{xml}{/exp:xsltransform}
{/exp:weblog:entries}
You can also use inline XML.
{exp:xsltransform xsl='xslt/index'}<xml><name type="first">Mark</name></xml>{/exp:xsltransform}
If all goes well, either should display:
Hello Mark
on your screen.
PHP4 & 5 are supported, but you'll need to figure out if you have the requisite libraries installed.
Feedback is not only welcome, it’s appreciated! Email feedback AT markjreeves DOT com.
Feel free to use XSLTransform 0.1 Beta on sites that you manage, as you wish. It’s not supported and not for redistribution.
© 2010 Mark J. Reeves