我在 xsl 转换器中使用这种方法创建图像: XSLT: Convert base64 data into image files
我的问题是,现在我要创建一个引用创建的图像的 IMG 标记。这是我所做的:
<!-- CREATE TEMP IMAGE -->
<xsl:variable name="b64" select="b64:new(string(./swe:Text/swe:value))"/>
<xsl:variable name="fos" select="fos:new(string('./temp.jpeg'))"/>
<xsl:value-of select="fos:write($fos, b64:getBinaryValue($b64))"/>
<xsl:value-of select="fos:close($fos)"/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat('./temp', '.jpeg')"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat('./temp', '.jpeg')"/>
</xsl:attribute>
<xsl:attribute name="align">TOP</xsl:attribute>
<xsl:attribute name="width">100</xsl:attribute>
<xsl:attribute name="height">75</xsl:attribute>
</img>
</a>
我从上面获取输出并将其显示在 JTextPane 中,但图像总是损坏。
我想这是相对路径的问题,但我不知道如何从 xsl 中获取绝对路径。
编辑:好的,结果我无法在 img 标签中引用相对图像,因为 JTextPanes 无法处理。我能够使用以下方法来完成这项工作:
<xsl:variable name="b64" select="b64:new(string(./swe:Text/swe:value))"/>
<xsl:variable name="fos" select="fos:new(string(concat('/temp/', @name, '.jpeg')))"/>
<xsl:value-of select="fos:write($fos, b64:getBinaryValue($b64))"/>
<xsl:value-of select="fos:close($fos)"/>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat('file:///C:/temp/', @name, '.jpeg')"/>
</xsl:attribute>
<xsl:attribute name="align">MIDDLE</xsl:attribute>
<xsl:attribute name="width">200</xsl:attribute>
<xsl:attribute name="height">150</xsl:attribute>
</img>
但我真的需要它是相对的或
我需要访问系统定义的临时目录。
有人知道怎么做吗?