saxon:base64Binary serialization method

The serialization method saxon:base64Binary is intended to be useful when creating binary output files, for example images. All serialization properties other than method are ignored.

As with the text 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 xs:base64Binary data type. The sequence of octets corresponding to this base64 value is written to the binary output file.

When invoking this method via an API, use the property value {http://saxon.sf.net/}base64Binary.

When using this serialization method, the omit-xml-declaration parameter is automatically set to yes.

In the following example, the image displays as a small red dot. Note that whitespace can be freely inserted into the base64Binary string.

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

It is of course possible to construct the base64Binary value programmatically. The functions in the EXPath binary module are useful for this purpose: see the EXPath binary function library. See also the Saxon extension function saxon:octets-to-base64Binary().

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 saxon:recognize-binary serialization parameter.

See also the saxon:hexBinary serialization method.