When loading xslt in XslCompiledTransform, I get a link to an object not installed in the object instance.
I pulled the following xslt from the database: -
<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:template match=\"/\">
<html>
<body>
<h2>My CD Collection</h2>
<table border=\"1\">
<tr bgcolor=\"#9acd32\">
<th style=\"text-align:left\">Title</th>
<th style=\"text-align:left\">Artist</th>
</tr>
<xsl:for-each select=\"catalog/cd\">
<tr>
<td>
<xsl:value-of select=\"title\"/>
</td>
<td>
<xsl:value-of select=\"artist\"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
and following xml from the database: -
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
When using the following code to convert xslt: -
public static string XsltTransform(string xmlContent, string xsltContent)
{
string result = string.Empty;
XmlTextReader xtr = new XmlTextReader(new StringReader(xsltContent));
xsltCompiled.Load(xtr);
using (StringReader srXml = new StringReader(xmlContent))
{
using (XmlReader xrXml = XmlReader.Create(srXml))
{
using (StringWriter sw = new StringWriter())
{
xsltCompiled.Transform(xrXml, null, sw);
result = sw.ToString();
}
}
}
return result;
}
But it gives an error " Object reference not set to an instance of an object" in the line: -
xsltCompiled.Load(xtr);
Any suggestions?
Update: Just add more, I get this after creating the XmlTextReader: -

source
share