I'm producing the body of an email via an xsl. I've been having a problem with the html nested inside a <table> tag not displaying correctly. With a bit of help from the good folks over at the asp.net forums, I've tracked the problem down to getting different results if I run the xsl via the debugger or via a compiled transform.
When I debug the xsl it produces
<table border="1" cellpadding="4" cellspacing="0" style="..." id="tmsEmailTable">
<tr>
<th width="50%" align="center"><b>Issue</b></th>
<th width="50%" align="center"><b>Resolution</b></th>
</tr>
<tr>
<td>Missing Acknowledgement date</td>
<td><p> Test test</p></td>
</tr>
<tr>
<td>Missing Agent and/or Seller signature</td>
....
</table>
And that's absolutely correct and displays perfectly if I save the result as an html file. But when I use xslt.Transform(..), where xslt is a compiled transform, it produces
<table border="1" cellpadding="4" cellspacing="0" style="..." id="tmsEmailTable">
<tr><th width="50%" align="center"><b>Issue</b></th><th width="50%" align="center"><b>Resolution</b></th></tr>
<tr>
<td>
Missing Acknowledgement date
</td>
<td></td>
</tr>
</table>
</p><p> Test test</p></td></tr><tr>
<td>Missing Agent and/or Seller signature</td>
<td>
.....
</table>
And to make it even more interesting, that extra </table> tag and the misplaced table data only occur on the first table row, but the table rows are generated by an xsl:for-each.
The relevant bit of the xsl is:
<table border="1" cellpadding="4" cellspacing="0" style="..." id="tmsEmailTable">
<tr>
<th width="50%" align="center">
<b>Issue</b>
</th>
<th width="50%" align="center">
<b>Resolution</b>
</th>
</tr>
<xsl:for-each select="emailbody/checklist/item">
<xsl:if test="string-length(select='issue')>0">
<tr>
<td>
<xsl:value-of select="issue" disable-output-escaping="yes" />
</td>
<td>
<xsl:value-of select="resolution" disable-output-escaping="yes" />
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
The code that generates the compiled transform and the (incorrect) output is:
Dim xslt As XslCompiledTransform = New XslCompiledTransform(True)
'Dim xslt As XslTransform = New XslTransform
xslt.Load(templatePath)
Dim objStream As Stream = New MemoryStream(UTF8Encoding.UTF8.GetBytes(xmlData))
Dim strbldrXML As StringBuilder = New StringBuilder()
Dim objXmlReader As XmlReader = XmlReader.Create(objStream)
Dim objXmlWriter As XmlWriter = XmlWriter.Create(strbldrXML)
xslt.Transform(objXmlReader, objXmlWriter)
I've checked that templatePath is pointing to the right file, and the source file I'm debugging the xsl against was copied from the xmlData parameter, so I know the same stuff is getting fed into it.
I've been chasing this for days, and I'm about ready to quit and go get a job at a fast food joint. I'm not wonderful with xsl in general, or xsl in .NET in particular. Somebody PLEASE tell me I'm doing something stupid....
Rebecca M. Riordan