Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2009, 12:33 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Question Convert ASCII (Byte[] Array) to Binary

How can I convert XML data in ASCII format, to a single element containing Base-64 data.

In other words, how can I convert a list of ASCII elements like the following:

<Document>
<data>208</data>
<data>207</data>
<data>17</data>
<data>224</data>
<data>161</data>
<data>177</data>
<data>26</data>
<data>225</data>
<data>0</data>
.
.
etc....
<Document>


To its base64 representation, something like this:

<Document>
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHB wgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL
</Document>



(the ASCII XML elements represent a small section of a word document)

Thanks
 
Old August 21st, 2009, 03:50 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First point: ASCII stops at 127. When you say ASCII, I assume you mean Unicode or perhaps iso-8859-1?

Base64 is an encoding of a byte stream. So I assume you want these codes treated as single bytes. In that case, it's actually immaterial whether they are ASCII codes or iso-8859-1 codes or anything else - they are just bytes.

There's no direct way of doing this in pure XSLT 1.0 or 2.0. Saxon however has an extension function that you could use:

http://www.saxonica.com/documentatio...e64binary.html

Calling

Code:
<xsl:value-of select="saxon:octets-to-base64Binary(/Document/data/xs:integer(.))"/>
should do the trick.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert bytes to byte[] array d-mart Java Basics 4 April 24th, 2009 10:09 AM
Converting an ASCII character to binary? skyraider Visual Basic 2005 Basics 0 May 7th, 2006 08:20 PM
Binary Data OR Byte() OR BitArray... to Integer pgjuun2 VB How-To 0 March 13th, 2005 11:52 PM
Differences between ASCII and Binary Files kuba C# 1 October 17th, 2004 07:22 PM
URGENT byte associated with the ASCII code shine Javascript How-To 0 July 5th, 2004 09:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.