RE: [xsl] Encoding base64 with XSLT

Subject: RE: [xsl] Encoding base64 with XSLT
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 19 Aug 2004 10:34:33 +0100
No, this can only be done using an extension function (or some very tortuous
low-level code). This is true even in XSLT 2.0/XPath 2.0, which supports the
xs:base64Binary data type but doesn't provide any function to get from a
sequence of octets to a base64Binary value.

I found that the following works with my current build of Saxon 8.1:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0"
xmlns:b64="net.sf.saxon.value.Base64BinaryValue"
exclude-result-prefixes="b64">
  <xsl:template match="/">
    <out>
      <a><xsl:value-of
select="b64:new(string-to-codepoints('M|ller'))"/></a>
    </out>
  </xsl:template>
</xsl:stylesheet>

Unfortunately it doesn't work with Saxon 8.0 because the mapping of an XPath
sequence of integers to a Java byte[] array isn't picked up: a different
constructor is selected instead. The basic code is there in Saxon, but
you'll have to write a Java wrapper method to invoke it.

I'll probably package this as a documented extension function in due course.

Michael Kay

> -----Original Message-----
> From: Michael Wiedmann [mailto:michael.wiedmann@xxxxxxxxx]
> Sent: 19 August 2004 10:05
> To: XSL List
> Subject: [xsl] Encoding base64 with XSLT
>
> An XML based addressbook has to be converted to LDIF (LDAP Data
> Interchange Format, RFC 2849) using an XSLT-stylesheet. LDIF does not
> allow non-ASCII characters, they have to be base64-encoded.
>
> E.g. given an element
>
> <lastname>M|ller</lastname>
>
> has to be written like
>
> sn:: TfxsbGVy
>
> instead of simply:
>
> sn: M|ller
>
> Is there any way to encode base64 with XSLT
>
> Michael

Current Thread