C# .NET - Stream a blob image through a XML / XSLT process
I am trying to display an image from database with a XML / XSLT technology
in a C# ASP.NET project. Here's a code sample showing how I use XSLT.
/// <summary>
/// Get HTML form xml
/// </summary>
/// <param name="xsltPath">the path</param>
/// <param name="xml">contain the xml</param>
/// <returns>the html</returns>
public string GetHtmlFrom_XML_XSL(string xsltPath, string xml)
{
xml = this.CleanString(xml);
MemoryStream stream = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(xml));
XPathDocument document = new XPathDocument(stream);
StringWriter writer = new StringWriter();
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xsltPath);
transform.Transform(document, null, writer);
return writer.ToString();
}
I now have to display an image from a blob in a SQL server... I have no
clue how to do that. I tried to use a .ashx handler within the xsl sheet
like that :
<img height="150" width="120">
<xsl:attribute
name="src">~/ImageHandler.ashx?atoContactId=<xsl:value-of
select="owner/picture" /></xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="owner/name" />
</xsl:attribute>
</img>
But of course, the html produced by the XSLT is streamed in the browser,
and the request HTTP of the src attribute is not processed. That's
resulting an empty image (red cross).
Is there any way of working or i should forget XML / XSLT for the
displaying of a blob image ?
Thanks in advance
No comments:
Post a Comment