I'm trying to convert my encoded base64 HTML content from an attribute and place it in the HTML content using XLST, hope somebody can help.
I have this string:
<p><b>Hello!</b><span>This is a span</span></p>
And this is the base64 encoded value:
PHA+PGI+SGVsbG8hPC9iPjxzcGFuPlRoaXMgaXMgYSBzcGFuPC9zcGFuPjwvcD4=
The XML data looks like this:
<Data Get="True">
<Result TextFlow="PHA+PGI+SGVsbG8hPC9iPjxzcGFuPlRoaXMgaXMgYSBzcGFuPC9zcGFuPjwvcD4=">
</Result>
</Data>
My last attempt was using this:
fn:cast($XML/Data/Result/@TextFlow,'xs:base64Binary','xs:String',false())
That code send this error:
Unknown function - Name and number or arguments do not match any function signature in the static context.
Thanks for your help!
There's no built-in capability in XSLT to do this.
Coming soon is the EXPath binary module:
http://expath.org/spec/binary
The bin:decode-string() function is what you need. We've got an implementation of this for Saxon but it's not integrated into the product yet. Meanwhile there is the extension function saxon:base64BinaryToString which is essentially the same:
http://www.saxonica.com/documentation/index.html#!functions/saxon/base64Binary-to-string
and which is available in Saxon-PE or higher.
Both functions take an argument of type xs:base64Binary; to convert a string in base64 to a value of this type, you use the constructor function xs:base64Binary(string). This requires XSLT 2.0 of course.
If your (decoded) string contains markup, then to copy it to the serialized HTML output you will need to use the deprecated disable-output-escaping="yes" option.
UPDATE (April 2019)
Recent releases of Saxon (the current release is 9.9) include the EXPath binary module as standard in Saxon-PE and higher editions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With