Stream a blob image through a XML / XSLT process

2019-09-01 18:24发布

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 to the xsl stylesheet</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 ?

标签: c# xml image xslt
1条回答
不美不萌又怎样
2楼-- · 2019-09-01 18:56

Here and here are the answers, how to read blobs from sql server.

In general, you have to read image from sql server first. Then you may use whatever technology you want to display it on page.

查看更多
登录 后发表回答