XSLT show a base64 as a image

删除回忆录丶 提交于 2019-12-11 23:13:15

问题


I have XML with a node containing a base64 format image. I've tried a lot of things but I can't generate a PDF with xslt-fo (apache).

This is my XML node to show:

.....
<pregunta101>
    <listaImagenes>
        <contenido>base64content</contenido>
        <ruta>c:\\ssss\\aaaa.jpg</ruta>
        <nombre>codigoFOTO</nombre>
    </listaImagenes>
    <listaImagenes>
.....

If I put the content instead of "contenido" variable, it shows it perfectly but I can't show it inside a foreach or directly read the xml node.

<fo:table-row number-columns-spanned="2">
    <fo:table-cell padding-right="10pt" padding-top="10pt" padding-left="10pt">
        <xsl:for-each select="solicitude/preguntasCheckList/pregunta101/listaImagenes">
            <xsl:value-of select="." />
            <fo:block text-align="left">
                <fo:external-graphic src="url('data:image/jpeg;base64,contenido)"/>                                             
            </fo:block>
        </xsl:for-each>
     </fo:table-cell>
</fo:table-row>

回答1:


Only tested with an online XML-FO Processor, but it should work if you change

<fo:external-graphic src="url('data:image/jpeg;base64,contenido)"/> 

into

<fo:external-graphic src="url('data:image/jpeg;base64,{contenido})"/>

With this adjustment I get for your example XML as input

<fo:external-graphic src="url('data:image/jpeg;base64,base64content)"/>

If you don't put the node/variable name into curly braces - {}, it will just be handled as literal value instead of being interpreted.

For reference: http://www.w3.org/TR/xslt#attribute-value-templates



来源:https://stackoverflow.com/questions/27025988/xslt-show-a-base64-as-a-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!