问题
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