i trying have single xml , @ 1 xsl stylesheet, contents of xml file below
<catalogue> <item> <item_id>1234</item_id> <item_desc>hi-fi sanio</item_desc> <price>12.50</price> <image>ivborw0kggoaaaansuheugaaaniaaaazcayaaadigvzlaaa</image> </item> <item> <item_id>4614</item_id> <item_desc>lace work</item_desc> <price>1.50</price> <image>qn0leqvr4no2dcxqtxxnhl0lt5jvtehln+5q+jckbjitlmhifkzbhhccybaiew</image> </item> <item> <item_id>614</item_id> <item_desc>bicycle</item_desc> <price>150</price> <image>jvtehln+5q+jckbjitlmhifkzbhhccybaiewleqvr4no2dcxqtxxnhl0l</image> </item> </catalogue>
the purpose able share xml file end users can view using web browser (ie11 now).
i'm using python , lxml create xml file have encoded image of items using base64 encoding , added image node each item. want embed images directly in xml when end user opens renders in browser. i.e no hyper-links
i @ loss how end-user browsers decode image node. won't have application whatsoever decode must either in xml or in associated stylesheet using browser.
does know if @ possible use xsl decode image embedded in xml document? examples can @ see how done.
generally ways encode , decode (embed) images (png/jpg) using xml alone or in conjunction xsl?
regards
if have base64 encoded data in xml , want embed img
rendering data in html can construct <img src="data:image/png;base64,{.}"/>
image element in xslt code data
uri (https://en.m.wikipedia.org/wiki/data_uri_scheme) (and of course proper mime type of image data), here example (assuming mime type image/png
):
<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html" doctype-public="about:legacy-compat" encoding="utf-8" indent="yes" /> <xsl:strip-space elements="*"/> <xsl:template match="/"> <html> <head> <title>data uri test</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="catalogue"> <table> <thead> <xsl:apply-templates select="item[1]" mode="header"/> </thead> <tbody> <xsl:apply-templates/> </tbody> </table> </xsl:template> <xsl:template match="item" mode="header"> <tr> <xsl:apply-templates mode="header"/> </tr> </xsl:template> <xsl:template match="item/*" mode="header"> <th> <xsl:value-of select="local-name()"/> </th> </xsl:template> <xsl:template match="item"> <tr> <xsl:apply-templates/> </tr> </xsl:template> <xsl:template match="item/*"> <td> <xsl:value-of select="."/> </td> </xsl:template> <xsl:template match="item/image"> <td> <img src="data:image/png;base64,{.}"/> </td> </xsl:template> </xsl:transform>
online @ http://home.arcor.de/martin.honnen/xslt/test2016080901.xml respectively http://home.arcor.de/martin.honnen/xslt/test2016080901.xsl, first image
element have used example image data wikipedia article , 4 browsers (ie, edge, chrome, firefox) render embedded image. sample data input xml not seem recognized image/png
, have tried image/jpeg
without success, not sure kind of image data is.
Comments
Post a Comment