Re: [xsl] Encoding base64 with XSLT

Subject: Re: [xsl] Encoding base64 with XSLT
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 19 Aug 2004 10:37:35 +0100
> Is there any way to encode base64 with XSLT

as is often cited XSLT is turing complete so the answer to any such
question is yes but the answer to "do you want to do it" may well be no.

It would be fairly painful in XSLT1 (even just finding the list of
characters from a string in order to start the encoding would be
inconvenient.)

If you are prepared to use xslt1 extensions it would be easier
(especially if you allowed yourself an extension to javascript or java
or something and directly called a base64 encoder:-)

It would be possible to code directly in xslt2.


> they have to be base64-encoded.

base64 encodes one byte stream as another so before you can encode teh
characters you have to encode them as a byte stream ie fix some encoding
such as utf8 or utf16 before you do the base 64 encoding. I'm not sure
I'd want to write a utf8 encoder in xslt1 either (similar problems to
doing the base64 encoder).

having said that the example you gave was

TfxsbGVy

which is the base64 encoding of the latin-1 encoded characters, which is
rather strange. Do you really want to use latin1? How would you encode
characters above position 127 in that case?

.....

I just looked at
http://www.faqs.org/rfcs/rfc2849.html
and I think that your example is wrong, the spec uses a datatype of

BASE64-UTF8-STRING

so presumably the characters should be utf8 encoded before base 64
encoding (so u-umlaut would take two bytes in the string that is being
base64 encoded not one).


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread