I have an XSL template that is a small section of an HTML email. The XSL section changes based on data, but the surrounding HTML does not. I would like to include this HTML in the XSL template. I tried the following approach, but get an exception because the tags in the EmailHeader.html are not closed. I tried using CDATA tags, but with no success.
My exception: Unexpected end of file has occurred. The following elements are not closed: td, tr, table, td, tr, table, body, html.
How can I include the html sections in the XSL template?
(Code samples have been simplified)
My XSL File:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/Email">
<xsl:copy-of select="document('EmailHeader.html')"></xsl:copy-of>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:25px"> </td>
<td style="width:550px; text-align:left; font-family:Arial; font-size:10pt; color:#444444">
<br /><br />
To <xsl:value-of select="FirstName"/> <xsl:value-of select="LastName"/>:
<br /><br />
Welcome, and thank you for enrolling...
</td>
<td style="width:25px"> </td>
</tr>
</table>
<xsl:copy-of select="document('EmailFooter.html')"></xsl:copy-of>
</xsl:template>
</xsl:transform>
EmailHeader.html:
<html xmlns="http://www.w3.org/1999/xhtml" style="background-color:#96A084">
<head>
<title></title>
</head>
<body style="background-color:#96A084; margin:0px; padding:0px">
<table border="0" cellpadding="0" cellspacing="0" width="630px" style="background-color:#96A084">
<tr>
<td>
EmailFooter.html:
<td style="width:15px"> </td>
</tr>
</table>
</body>
</html>
What you could do, is create your complete Email template in a separate file, and then pass the body of the email to it as a parameter. For example, save the following XSLT in a file called EmailTemplate.xslt
Next, amend your original XSLT to import this file, and then call the named Email template with the HTML for the email body as a parameter
So, when you apply this XSLT to the following XML
The following should be output