Hi tom,
I have this xsl to convert base64 to image file, I use Saxon and java.
I use this template for transforming xhtml word to docbook, sometimes
the image files are coded in base64, I extract the content and save
the file with generate-id name, after this I put the reference in the
docbook file.
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://docbook.org/ns/docbook"
xmlns:b64="net.sf.saxon.value.Base64BinaryValue"
xmlns:fos="java.io.FileOutputStream"
xpath-default-namespace="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="#all">
<xsl:template match="img">
<xsl:variable name="contingut"
select="substring-after(@src,'data:image/*;base64,')"/>
<xsl:variable name="img" select="concat(generate-id(),'.jpg')"/>
<xsl:variable name="b64" select="b64:new(string($contingut))"/>
<xsl:variable name="fos"
select="fos:new(concat($dir-sortida,'/',string($img)))"/>
<xsl:value-of select="fos:write($fos, b64:getBinaryValue($b64))"/>
<xsl:value-of select="fos:close($fos)"/>
<para>
<mediaobject>
<imageobject>
<imagedata fileref="{$img}" format="img"/>
</imageobject>
</mediaobject>
</para>
</xsl:template>
</xsl:stylesheet>
2011/4/27 Martin Honnen <Martin(_dot_)Honnen(_at_)gmx(_dot_)de>:
tom tom wrote:
I need to take a jpeg / gif file as input and output it as base 64.
Is there a way to do this using XSLT 2 (Saxon 9+) / extension functions.
There is
http://www.saxonica.com/documentation/extensions/functions/octetstobase64binary.xml
and by calling into Java you can probably read in the file and get the
sequence of octets to feed to that function.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--