XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSL-fo and how to line feed th... (1)
-> + Houston we have a problem (2)
-> + XSL-FO PDF generation (2)
-> + StylusStudio - pick XSLT 1.0 b... (6)
-> - Stylus Studio 2010 debugging f... (1)
-> - Drop down menu List / Option M... (1)
-> - XML transformation using Java ... (1)
-> + i can't to find XSLT editor in... (2)
-> - Copy xml input as value of an ... (1)
-> - Remove Name space from the Tab... (1)
-> - CGI formatted URL with name/va... (1)
-> - Problem with counting (1)
-> + for-each loop is only returnin... (3)
-> - sort date but some dates may b... (1)
-> - Entity Conversion (1)
-> - How can I build an xml convert... (1)
-> + Little Help (2)
-> + how do I merge nodes to one sc... (2)
-> - beginner help xslt and xpath (1)
-> - Convert XML Feed to CSV/SQL/XL... (1)
-> - Working with text node. (1)
-> - No Topic (1)
-> - API for XSLT Converter for .NE... (1)
-> - Getting started (1)
-> + saxon sql extensions - mysql a... (2)
-> - How do I copy and create new e... (1)
-> + substring-before and sums (3)
-> + Parsing special characters in ... (2)
-> + Schema - Require attribute in ... (2)
-> - Edit existing XSL files when n... (1)
-> + How can I use one single XSLT ... (2)
-> - Default selection of value in ... (1)
-> - Problem with watermark in pdf ... (1)
-> + XSLT Parameter Values dialog n... (3)
-> + Value of File Name is not acce... (10)
-> - Need help with a complex table... (1)
-> - How to replace all nordic char... (1)
-> - XSLT java heap space error wit... (1)
-> - Table Overflow to next page (1)
-> - Using XSLT 2.0 to define custo... (1)
-> - "standalone" attribute and xs... (1)
-> + Standardizing IP addresses (2)
-> + Programmatically changing page... (6)
-> + Can Stylus generate XSLT if so... (5)
-> + Extraction based on NODE Name. (2)
-> + NO XSLT:WYSIWYG (2)
-> + determine condition at run tim... (2)
-> - How to reduce top margin in ev... (1)
-> + need help on xsl looping (4)
-> - Convert Symbol to Element (1)
-> + Separator -only- between field... (3)
-> + DocBook (9)
-> + First Occurance of Alphabet (2)
-> + XSL:Key and Document (2)
-> + Excel Macro using XSLT (2)
-> + Add missing element and attrib... (2)
-> + XSL: Stop Count at First Match (2)
-> + XSD to EDI (4)
-> + How to access data from nested... (2)
-> + Simple division of XML file (2)
-> - XML to Flat File (1)
-> + Dispalying data whith xsl:for ... (3)
-> - distinct nodes - into 3 column... (1)
-> + Newbie at XML (2)
-> + XSL Not Working (3)
-> + to draw table using xsl (2)
-> - Base64 decoder (5)
-> ->Base64 decoder - easier s...
-> ->Base64 decoder - easier s...
-> ->Base64 decoder - easier s...
-> ->Base64 decoder - easier s...
-> + How to create a hidden sheet u... (3)
-> + XML Reports (2)
-> + Copying image files from one d... (2)
-> + XML conversion to RSS (2)
-> + Inserting Image (2)
-> + Xml to Pdf using Xsl (2)
-> + Using a parameter (or similar)... (2)
-> + How to avoid creating empty xm... (2)
-> + how to read txt files in xml (2)
-> + Limit records to 4 per page. P... (4)
-> + XSLT Mapping Based on JDK5 (2)
-> + XML Mappin (2)
-> + Format Datetime with xslt (3)
-> + Cell border missing (2)
-> + XSL: Key (not matches) (5)
-> + Loop through each char in stri... (2)
-> + What is the best way to sum va... (3)
-> + xslt sort help (2)
-> + getting the count (2)
-> + XSL dynamic variables (5)
-> + XSL:Key use (3)
-> + Help With Updating Attributes ... (8)
-> + GETTING COUNT AND POSITION usi... (3)
-> - Hi Everyone !! (1)
-> + Graph Traversal (Keep track of... (2)
-> + XSL IF with sum (2)
-> + Param not incrementing (2)
-> + Iterating through value tags (3)
-> + URGENT :::: Remove the name sp... (2)
-> + Pass new param values to ASP O... (2)
-> + Detect Browser Version in XSL (2)
-> + xslt result-document (2)
-> + Unique nodes based on two attr... (3)
-- Previous [181-200] [201-220] [221-240] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
(Deleted User) Subject: Base64 decoder
Author: (Deleted User)
Date: 16 Sep 2009 03:47 AM
Good morning from the Netherlands,

I am now perfectly able to encode files to base64 format and upload them to an SQL application. This application is missing however an export functionality, so I am now trying to get the data from the database with an xquery and transform the base64 encoded field back to binary format.

I found this xsl sheet on the Internet, should I able to do the trick with this sheet? For now I am not able to run it due to a "no character data is allowed between top level elements", but I don't know what's the problem and searching on the Stylus form returns a system error since yesterday.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:variable name="datamap" select="document('datamap.xml')" />
<xsl:template match="/">
<xsl:variable name="base64String1" select="'SGVsbG8gV29ybGQh'" />
<xsl:variable name="base64String2" select="'VGhpcyBpcyBiYXNlNjQgZW5jb2Rpbmc='" />
<xsl:variable name="base64String3" select="'Ymx1ZQ=='" />
<xsl:call-template name="convertBase64ToAscii">
<xsl:with-param name="base64String" select="$base64String1" />
</xsl:call-template>
<xsl:text>------------------------</xsl:text>
<xsl:call-template name="convertBase64ToAscii">
<xsl:with-param name="base64String" select="$base64String2" />
</xsl:call-template>
<xsl:text>------------------------</xsl:text>
<xsl:call-template name="convertBase64ToAscii">
<xsl:with-param name="base64String" select="$base64String3" />
</xsl:call-template>
<xsl:text>------------------------</xsl:text>
</xsl:template>
<!-- Template to convert the base64 string to ascii representation
-->
<xsl:template name="convertBase64ToAscii">
<xsl:param name="base64String" />
<!-- execute if last 2 characters do not contain = character
-->
<xsl:if test="not(contains(substring($base64String, string-length($base64String) - 1), '='))">
<xsl:variable name="binaryBase64String">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="$base64String" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="$binaryBase64String" />
</xsl:call-template>
</xsl:if>
<!-- extract last two characters
-->
<xsl:variable name="secondLastChar" select="substring($base64String, string-length($base64String) - 1, 1)" />
<xsl:variable name="lastChar" select="substring($base64String, string-length($base64String), 1)" /> <!-- execute if 2nd last character is not a =, and last character is =
-->
<xsl:if test="($secondLastChar != '=') and ($lastChar = '=')">
<xsl:variable name="binaryBase64String">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="substring($base64String, 1, string-length($base64String) - 4)" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="$binaryBase64String" />
</xsl:call-template>
<xsl:variable name="partialBinary">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="substring($base64String, string-length($base64String) - 3, 3)" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="substring($partialBinary, 1, 8)" />
</xsl:call-template>
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="substring($partialBinary, 9, 8)" />
</xsl:call-template>
</xsl:if>
<!-- execute if last 2 characters are both =
-->
<xsl:if test="($secondLastChar = '=') and ($lastChar = '=')">
<xsl:variable name="binaryBase64String">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="substring($base64String, 1, string-length($base64String) - 4)" />
</xsl:call-template>
</xsl:variable>
- <xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="$binaryBase64String" />
</xsl:call-template>
<xsl:variable name="partialBinary">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="substring($base64String, string-length($base64String) - 3, 2)" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="substring($partialBinary, 1, 8)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Template to convert the base64 binary string to ascii representation
-->
<xsl:template name="base64BinaryStringToAscii">
<xsl:param name="binaryString" />
<xsl:if test="substring($binaryString, 1, 8) != ''">
<xsl:variable name="asciiDecimal">
<xsl:call-template name="binaryToDecimal">
<xsl:with-param name="binary" select="substring($binaryString, 1, 8)" />
<xsl:with-param name="sum" select="0" />
<xsl:with-param name="index" select="0" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$datamap/datamap/asciidecimal/char[decimal = $asciiDecimal]/ascii" />
<xsl:call-template name="base64BinaryStringToAscii">
<xsl:with-param name="binaryString" select="substring($binaryString, 9)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Template to convert a binary number to decimal representation; this template calls template pow
-->
<xsl:template name="binaryToDecimal">
<xsl:param name="binary" />
<xsl:param name="sum" />
<xsl:param name="index" />
<xsl:if test="substring($binary,string-length($binary) - 1) != ''">
<xsl:variable name="power">
<xsl:call-template name="pow">
<xsl:with-param name="m" select="2" />
<xsl:with-param name="n" select="$index" />
<xsl:with-param name="result" select="1" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="binaryToDecimal">
<xsl:with-param name="binary" select="substring($binary, 1, string-length($binary) - 1)" />
<xsl:with-param name="sum" select="$sum + substring($binary,string-length($binary)) * $power" />
<xsl:with-param name="index" select="$index + 1" />
</xsl:call-template>
</xsl:if>
<xsl:if test="substring($binary,string-length($binary) - 1) = ''">
<xsl:value-of select="$sum" />
</xsl:if>
</xsl:template>
<!-- Template to calculate m to the power n
-->
<xsl:template name="pow">
<xsl:param name="m" />
<xsl:param name="n" />
<xsl:param name="result" />
<xsl:if test="$n >= 1">
<xsl:call-template name="pow">
<xsl:with-param name="m" select="$m" />
<xsl:with-param name="n" select="$n - 1" />
<xsl:with-param name="result" select="$result * $m" />
</xsl:call-template>
</xsl:if>
<xsl:if test="$n = 0">
<xsl:value-of select="$result" />
</xsl:if>
</xsl:template>
<!-- Template to convert a base64 string to binary representation; this template calls template decimalToBinary
-->
<xsl:template name="base64StringToBinary">
<xsl:param name="string" />
<xsl:if test="substring($string, 1, 1) != ''">
<xsl:variable name="binary">
<xsl:call-template name="decimalToBinary">
<xsl:with-param name="decimal" select="$datamap/datamap/decimalbase64/char[base64 = substring($string, 1, 1)]/value" />
<xsl:with-param name="prev" select="''" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="padZeros">
<xsl:with-param name="string" select="$binary" />
<xsl:with-param name="no" select="6 - string-length($binary)" />
</xsl:call-template>
</xsl:if>
<xsl:if test="substring($string, 2) != ''">
<xsl:call-template name="base64StringToBinary">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Template to left pad a binary string, with the specified no of 0s, to make it of length 6
-->
- <xsl:template name="padZeros">
<xsl:param name="string" />
<xsl:param name="no" />
<xsl:if test="$no > 0">
<xsl:call-template name="padZeros">
<xsl:with-param name="string" select="concat('0', $string)" />
<xsl:with-param name="no" select="6 - string-length($string) - 1" />
</xsl:call-template>
</xsl:if>
<xsl:if test="$no = 0">
<xsl:value-of select="$string" />
</xsl:if>
</xsl:template>
<!-- Template to convert a decimal number to binary representation
-->
<xsl:template name="decimalToBinary">
<xsl:param name="decimal" />
<xsl:param name="prev" />
<xsl:variable name="divresult" select="floor($decimal div 2)" />
<xsl:variable name="modresult" select="$decimal mod 2" />
<xsl:choose>
<xsl:when test="$divresult > 1">
<xsl:call-template name="decimalToBinary">
<xsl:with-param name="decimal" select="$divresult" />
<xsl:with-param name="prev" select="concat($modresult, $prev)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$divresult = 0">
<xsl:value-of select="concat($modresult, $prev)" />
</xsl:when>
<xsl:when test="$divresult = 1">
<xsl:text>1</xsl:text>
<xsl:value-of select="concat($modresult, $prev)" />
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Thanks again,


Cynthia

Postnext
(Deleted User) Subject: Base64 decoder - easier solution?
Author: (Deleted User)
Date: 16 Sep 2009 09:54 AM
Dear Stylussees,

I think I found a far more easy solution on your own website, see http://www.stylusstudio.com/binary_xml.html. I tested the emaple on your own website, but it is not working. Could it be that it's not working, because I don't have the Base-64 Deployment Adapter? I have a full license of Stylus Studio Enterprise.

Thanks,



Cynthia

Postnext
Tony LavinioSubject: Base64 decoder - easier solution?
Author: Tony Lavinio
Date: 17 Sep 2009 01:52 AM
If you are running from within Stylus Studio, you have a development-time
license to the converters.

First, were you able to get the examples from the website working?
(note that the 'adapter:' prefix is now 'converter:', but both should
work).

Postnext
(Deleted User) Subject: Base64 decoder - easier solution?
Author: (Deleted User)
Date: 18 Sep 2009 03:01 PM
I got the example working, but only after I installed the trial XML Converter - Java (or flat file converter). I thought it would be like you said, I have a Stylus Enterprise license, so I should be able to use the converters from within Stylus.

Ever since I tried to compile a Java coded XSLT Stylus is telling me though this license is past its evaluation period.

How can I run the base64 decoding XSLT without an extra license from within Stylus?

Thanks again,


Cynthia

Posttop
Tony LavinioSubject: Base64 decoder - easier solution?
Author: Tony Lavinio
Date: 18 Sep 2009 09:41 PM
You were getting a license error from within Stylus Studio for the
converters?

Please send a screenshot showing that, along with your license number
to stylus-field-report@progress.com, and we'll look to see what has
happened.

Is it possible you have a mismatch between the Stylus Studio version
and a separately-installed XML Converters license?

Within Enterprise Stylus Studio, you should have full access to the
XML Converters and XQuery engine.

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.