<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="extensions" page="output-extras" subpage="base64Binary-method"/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: The saxon:base64Binary serialization method</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: The saxon:base64Binary serialization method"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>The saxon:base64Binary serialization method</h1> <p><i>Requires Saxon-PE</i></p> <p>An additional serialization method <code>saxon:base64Binary</code> is available. This is intended to be useful when creating binary output files, for example images. All serialization properties other than <code>method</code> are ignored.</p> <p>As with the <code>text</code> output method, all nodes in the result tree other than text nodes are ignored. Each text node must hold a string that is in the lexical space of the <code>xs:base64Binary</code> data type. The sequence of octets corresponding to this base64 value is written to the binary output file.</p> <p>When invoking this method via an API, use the property value "{http://saxon.sf.net/}base64Binary".</p> <p>When using this serialization method, the <code>omit-xml-declaration</code> parameter is automatically set to "yes".</p> <div class="codeblock" style="border: solid thin; background-color: #B1CCC7; padding: 2px"> <pre> <code><xsl:template name="main"> <html> <head> <title>An image</title> </head> <body> <h1>An image</h1> <p><img src="image.gif"/></p> </body> </html> <xsl:result-document method="saxon:base64Binary" href="image.gif" media-type="image/gif"> <xsl:text>iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAA LEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBH SU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH 4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg== </xsl:text> </xsl:result-document> </xsl:template> </code> </pre> </div> <p><i>The image here displays as a small red dot. Note that whitespace can be freely inserted into the base64Binary string.</i></p> <p>It is of course possible to construct the base64Binary value programmatically. The extension function <a class="bodylink" href="../../extensions/functions/octetstobase64binary.xml">saxon:octets-to-base64Binary</a> may be useful to achieve this.</p> <p>When writing output that is not entirely binary, but contains mixed binary and text, it may be more convenient to use the text output method with the <a class="bodylink" href="../../extensions/output-extras/recognize-binary.xml">saxon:recognize-binary</a> serialization property.</p> <p>See also the <a class="bodylink" href="../../extensions/output-extras/hexBinary-method.xml">saxon:hexBinary</a> serialization method.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="hexBinary-method.xml">Next</a></p> </td> </tr> </table> </body> </html>