使用 XSLT 在 HTML(base64) 中显示图像

Display image in HTML(base64) using XSLT

我试图在转换为 base64 后以 HTMl 格式显示 JPG 图像。我正在 XSLT 代码中尝试此操作。我用 concat 和 write-binary 尝试了几个选项,但其中 none 似乎有效。 这是否支持使用 XSLT?是否有任何内置功能可用?

<img>
            <xsl:attribute name="src">
              <!--xsl:value-of select="concat('data:image/gif;base64,',xPath)"/-->
              <xsl:value-of select="file:write-binary(C:\MyDesktop\Desktop\allImages\download.jpg, xs:base64Binary(string()))"/>
            </xsl:attribute>
          </img>

假设您可以访问例如支持 EXPath 文件模块的 Saxon PE 或 EE http://expath.org/spec/file then I think it suffices to construct a data URI https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs using the file:read-binary method http://expath.org/spec/file#fn.read-binary:

在 XSLT 中,您可以使用例如

<img src="data:image/jpeg;base64,{file:read-binary('C:\MyDesktop\Desktop\allImages\download.jpg')}"/>

构造一个 HTML img 元素,将数据 URI 中内联的图像数据设置为 src 属性值。

样式表显然需要声明模块的名称空间,例如

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:file="http://expath.org/ns/file"
    exclude-result-prefixes="#all" version="3.0">