Topic
  • 42 replies
  • Latest Post - ‏2015-06-01T09:36:42Z by HermannSW
HermannSW
HermannSW
4647 Posts

Pinned topic DataPower "binary" node type (binaryNode)

‏2011-01-18T20:40:13Z |

DataPower "binary" node type (binaryNode)


DataPower node types

DataPower does support the 7 node types from XPath 1.0 data model [1]:
  • root, element
  • text
  • attribute, namespace
  • processing instruction, comment

In addition DataPower provides a proprietary node type called binaryNode.
This node type is used for containing binary data while processing XML files, eg. for crypto purposes.

binaryNode is not a first class member of the DataPower node types.
You may not do everything with it and expect it to work.
For example passing a binaryNode as argument to a user defined func:function or a template might not give the results you expect.
This is working as designed as binaryNode is intended for specific uses only.

Examples of how a binaryNode can be created

  • dp:binary-decode('VGVzdA==')
  • <dp:url-open target="..." response="binaryNode" .../>
  • <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
  • ...

xsl:copy-of and dp:binary-encode

binaryNode nodes can be copied by xsl:copy-of.
And they can be encoded by dp:binary-encode() which base64 encodes the binary data and therefore returns a xs:string.

xsl:value-of for binaryNode

Trying to access the value of a binaryNode by

<xsl:value-of select=
"dp:binary-decode('VGVzdA==')"/>

you will not get "Test" as you might expect ("VGVzdA==" is base64 encoding of "Test") but get "***BINARY NODE***" instead.
Since a binaryNode may contain arbitrary binary data this is the designed behaviour.

how to get the "real" value

As part of the "hex-to-text" template on this [2] slide of last years WSTE presentation a method was shown how to get the "real" value out of a binaryNode:
1) store the binaryNode into a xsl:variable ($raw)
2) do <xsl:value-of select="$raw"/> then

Security considerations -- validation

If you have the contents of the binary data under control you may just use above method.
But some binary data may affect the stability of the DataPower appliance if accessed that way.
Therefore eg. getting a HTML page which you do not have unter control via

<dp:url-open target=
"http://..." response=
"binaryNode" .../>

is not a good idea since getting the value of the binaryNode return by above method bypassed the input validation of DataPower
(UTF-8 validation is the default validation if no other encoding is specified in the input XML file).

Therefore below two functions dp:value-base64() and dp:value-hex() allow to pass the request for
validation against an encoding as 2nd argument (either "ascii" or "utf-8").
The validation is done by regular expression matching against the hex representation string.

dp:value-base64(base64string, encoding)

The three stylesheets and binary input files (41, c3a4, c080) are contained in attached .zip file.

The binary input files just contain the binary data indicated by their name, eg:

$ od -Ax -tx1 c3a4 000000 c3 a4 000002 $


These are the different outputs generated by dp:value-base64(), with no validation or validation against UTF-8 or ASCII:
. 41 c3a4 c080
value-base64.xsl "A" "&#228;" "&#0;"
value-base64-utf-8.xsl "A" "&#228;" ""
value-base64-ascii.xsl "A" "" ""


Btw, c080 is an overlong representation of the 0x00 byte and therefore not valid UTF-8, but valid modified UTF-8 [3].

This is the stylesheet demonstrating UTF-8 validation as part of dp:value-base64() -- if validation fails an empty string is returned:

$ cat value-base64_utf-8.xsl <xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <xsl:include href=
"binaryNode.xsl"/>   <dp:input-mapping   href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <xsl:value-of select=
"dp:value-base64( dp:binary-encode(/object/message/child::node()),
'utf-8')
"/> </xsl:template> </xsl:stylesheet> $


dp:value-hex(hexString, encoding)

The three stylesheets and input files (41.xml, c3a4.xml, c080.xml) are contained in attached .zip file.

The input files just contain the hex representation indicated by their name, eg:

$ cat c3a4.xml <y>c 3 A 4 </y> $


These are the different outputs generated by dp:value-hex(), with no validation or validation against UTF-8 or ASCII:
. 41.xml c3a4.xml c080.xml
value-hex.xsl "A" "&#228;" "&#0;"
value-hex-utf-8.xsl "A" "&#228;" ""
value-hex-ascii.xsl "A" "" ""


This is the stylesheet demonstrating UTF-8 validation as part of dp:value-hex() -- if validation fails an empty string is returned:

$ cat value-hex_utf-8.xsl <xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <xsl:include href=
"binaryNode.xsl"/>   <xsl:template match=
"/"> <xsl:value-of select=
"dp:value-hex(dp:normalize-hex(.),'utf-8')"/> </xsl:template> </xsl:stylesheet> $


Magnifying glass -- DataPower internal data representation is UTF-8


Input data sample for German Umlaute, UTF-8 encoded:

$ cat umlaute-u.xml <?xml version=
"1.0" encoding=
"UTF-8"?> <umlaute>äöüÄÖÜß</umlaute> $


Input data sample for German Umlaute, ISO-8859-1 encoded:

$ cat umlaute-i.xml <?xml version=
"1.0" encoding=
"ISO-8859-1"?> <umlaute>�������</umlaute> $


The output of magnifyingGlass.xsl (the internal representation of DataPower for both input files) is the same -- it is UTF-8 encoded:

$ od -Ax -tx1 umlaute-u.xml.out 000000 c3 a4 c3 b6 c3 bc c3 84 c3 96 c3 9c c3 9f 00000e $ $ od -Ax -tx1 umlaute-i.xml.out 000000 c3 a4 c3 b6 c3 bc c3 84 c3 96 c3 9c c3 9f 00000e $


magnifyingGlass.xsl -- wrap input into a binary node and then output it "as is" by using
"store:///pkcs7-convert-input.ffd" as dp:output-mapping (just put into <object><mesage>...</message></object>):

$ cat magnifyingGlass.xsl <xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" xmlns:func=
"http://exslt.org/functions" xmlns:exslt=
"http://exslt.org/common" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <dp:output-mapping  href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <object> <message> <xsl:variable name=
"inputAsBinaryNode" select=
"dp:binary-decode(dp:binary-encode(.))"/>   <xsl:copy-of select=
"$inputAsBinaryNode"/> </message> </object> </xsl:template> </xsl:stylesheet> $


Termination at first 0x00 byte

dp:value-base64() and dp:value-hex() both terminate the output at the first 0x00 byte (&#0;) of the data.
For example the result of "dp:value-hex('41424300313233')" is "ABC".

As you have seen in previous magnifyingGlass.xsl stylesheet you may use dp:output-mapping to deal with 0x00 bytes without termination:

$ od -Ax -tcx1 zero.xsl.out 000000   A   B   C  \0   1   2   3 41 42 43 00 31 32 33 000007 $


This is the stylesheet generating above output, has to be referenced by a binary transform action:

$ cat zero.xsl <xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <dp:output-mapping  href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <object> <message> <xsl:variable name=
"withZero" select=
"dp:radix-convert('41424300313233',16,64)"/>   <xsl:copy-of select=
"dp:binary-decode($withZero)"/> </message> </object> </xsl:template> </xsl:stylesheet> $


store:///pkcs7-convert-input.ffd


You may use this file in dp:input-mapping as in value-base64.xsl, value-base64_ascii.xsl or value-base64_utf-8.xsl above.

... <!-- This FFD converts the input into an XML tree like 

this:   <object> <message>***binary data***</message> </object> --> ...


But you may also use it as dp:output-mapping like in magnifyingGlass.xsl or zero.xsl above.

store:///pkcs7-convert-input.ffd is used by five strore:///pkcs7... stylesheets.

binaryNode.xsl


You may include binaryNode.xsl to have access to this functionality:
  • dp:value-base64(string, encoding) --> provide "value" of base64 encoded string, validate against encoding (utf-8/ascii) if requested
  • dp:value-hex(string, encoding) --> provide "value" of hex encoded string, validate against encoding (utf-8/ascii) if requested
  • dp:normalize-hex(hexStringWithWhiteSpace) --> normalize
  • dp:validate-hex(hexString) --> UTF-8 validate the input string
  • dp:validate-base64(base64string) --> UTF-8 validate the input string

These are the steps to get the value of a binary node,
  • access it by ".../child::node()"
  • then dp:binary-encode() it
  • and then use dp:value-base64()
like this:

... <xsl:variable name=
"binaryNode" select=
"/object/message/child::node()"/>   <xsl:value-of select=
"dp:value-base64( dp:binary-encode($binaryNode),
'utf-8')
"/> ...


binaryNode.xsl:

<xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" xmlns:func=
"http://exslt.org/functions" xmlns:regexp=
"http://exslt.org/regular-expressions" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <!-- dp:radix-convert(_,64,16) generates upper 

case characters. Therefore normalize hex string to upper 

case characters and additionally eliminate all white space. --> <func:function name=
"dp:normalize-hex"> <xsl:param name=
"str"/>   <func:result select=
"translate(normalize-space($str),'abcdef ','ABCDEF')" /> </func:function>   <!-- from http:
//www.w3.org/International/questions/qa-forms-utf-8.en.php   $field =~ m/\A( [\x09\x0A\x0D\x20-\x7E]            # ASCII | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-

byte |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]
{2
}  # straight 3-

byte |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates |  \xF0[\x90-\xBF][\x80-\xBF]
{2
}     # planes 1-3 | [\xF1-\xF3][\x80-\xBF]
{3
}          # planes 4-15 |  \xF4[\x80-\x8F][\x80-\xBF]
{2
}     # plane 16 )*\z/x; -->   <!-- 

this excludes most of the ASCII control characters --> <xsl:variable name=
"ASCII_char" select=
"'09|0A|0D|[2-6][0-9A-F]|7[0-9A-E]'" />   <xsl:variable name=
"UTF-8_char" select=
"concat( $ASCII_char, 
'|C[2-9A-F][89AB][0-9A-F]|D[0-9A-F][89AB][0-9A-F]', 
'|E[AB][0-9A-F][89AB][0-9A-F]', 
'|E[1-9A-CEF][89AB][0-9A-F][89AB][0-9A-F]', 
'|ED[89][0-9A-F][89AB][0-9A-F]', 
'|F0[9AB][0-9A-F][89AB][0-9A-F][89AB][0-9A-F]', 
'|F[1-3][89AB][0-9A-F][89AB][0-9A-F][89AB][0-9A-F]', 
'|F48[0-9A-F][89AB][0-9A-F][89AB][0-9A-F]' )
" />     <!-- validate that $hexString is a valid UTF-8 string --> <func:function name=
"dp:validate-hex"> <xsl:variable name=
"hexString" />   <func:result select=
"regexp:test(dp:normalize-hex($hexString), concat(
'^(',$UTF-8_char,
')*$'), 
'')
"/> </func:function> <!-- validate that $base64string is a valid UTF-8 string --> <func:function name=
"dp:validate-base64"> <xsl:variable name=
"base64string" />   <func:result select=
"regexp:test(dp:radix-convert($base64string,64,16), concat(
'^(',$UTF-8_char,
')*$'), 
'')
"/> </func:function>     <func:function name=
"dp:value"> <xsl:param name=
"base64string"/> <xsl:param name=
"hexString" select=
"''"/> <xsl:param name=
"validateString" select=
"''"/>   <xsl:variable name=
"raw" select=
"dp:binary-decode($base64string)"/>   <func:result> <xsl:choose> <xsl:when test=
"$validateString"> <xsl:

if test=
"regexp:test($hexString, $validateString, 
'')
"> <xsl:value-of select=
"$raw"/> </xsl:if> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"$raw"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>     <func:function name=
"dp:value-base64"> <xsl:param name=
"base64string"/> <xsl:param name=
"validate" select=
"''"/>   <func:result> <xsl:choose> <xsl:when test=
"$validate"> <xsl:variable name=
"hexString" select=
"dp:radix-convert($base64string,64,16)"/>   <xsl:choose> <xsl:when test=
"$validate = 'ascii'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$ASCII_char,
')*$'))
"/> </xsl:when>   <xsl:when test=
"$validate = 'utf-8'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$UTF-8_char,
')*$'))
"/> </xsl:when> </xsl:choose> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"dp:value($base64string)"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>   <func:function name=
"dp:value-hex"> <xsl:param name=
"hexString"/> <xsl:param name=
"validate" select=
"''"/>   <xsl:variable name=
"base64string" select=
"dp:radix-convert($hexString,16,64)"/>   <func:result> <xsl:choose> <xsl:when test=
"$validate"> <xsl:choose> <xsl:when test=
"$validate = 'ascii'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$ASCII_char,
')*$'))
"/> </xsl:when>   <xsl:when test=
"$validate = 'utf-8'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$UTF-8_char,
')*$'))
"/> </xsl:when> </xsl:choose> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"dp:value($base64string)"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>   </xsl:stylesheet>

Appendix


[1] http://www.w3.org/TR/xpath/#data-model
[2] http://www-01.ibm.com/support/docview.wss?uid=swg27019118&aid=1#page=5
[3] http://en.wikipedia.org/wiki/Utf-8#Modified_UTF-8

Hermann.
Updated on 2012-11-21T10:16:13Z at 2012-11-21T10:16:13Z by HermannSW
  • cltnc28269
    cltnc28269
    4 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-05-29T01:28:15Z  
    Hi there!

    I am working on an urgent requirement to convert a SOAP Response with MTOM attachment to a REST/HTTP response with MIME attachment.

    The following XSLT returns only half of the entire PDF/binary content. I noticed "Transfer-Encoding: chunked" in the HTTP header. Not sure at this point what could be wrong. I need to return the pdf.

    <xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dp="http://www.datapower.com/extensions" xmlns:dpquery="http://www.datapower.com/param/query" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.1">
    <xsl:output encoding="utf-8" omit-xml-declaration="yes" method="html" indent="no"/>
    <xsl:template match="/">
    <dp:set-http-response-header name="'Content-Type'" value="'application/pdf' "/>
    <dp:set-http-response-header name="'Content-Transfer-Encoding'" value="'binary' "/>
    <xsl:variable name="manifest" select="dp:variable('var://context/INPUT/attachment-manifest')"/>
    <xsl:variable name="pdf">
    <xsl:for-each select="$manifest/*/
    /">
    <xsl:variable name="filename" select="./uri/text()"/>
    <xsl:variable name="cid" select="concat($filename,'?Encode=base64')"/>
    <xsl:variable name="base64">
    <dp:url-open target="{$cid}"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">****(base64)****: <xsl:value-of select="$base64"/>
    </xsl:message>
    <xsl:variable name="raw" select="dp:binary-decode($base64)"/>
    <xsl:message dp:priority="debug">****(raw)****: <xsl:value-of select="$raw"/>
    </xsl:message>
    <xsl:value-of select="$raw"/>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="$pdf"/>
    </xsl:template>
    </xsl:stylesheet>
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-05-30T20:27:54Z  
    Hi there!

    I am working on an urgent requirement to convert a SOAP Response with MTOM attachment to a REST/HTTP response with MIME attachment.

    The following XSLT returns only half of the entire PDF/binary content. I noticed "Transfer-Encoding: chunked" in the HTTP header. Not sure at this point what could be wrong. I need to return the pdf.

    <xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dp="http://www.datapower.com/extensions" xmlns:dpquery="http://www.datapower.com/param/query" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.1">
    <xsl:output encoding="utf-8" omit-xml-declaration="yes" method="html" indent="no"/>
    <xsl:template match="/">
    <dp:set-http-response-header name="'Content-Type'" value="'application/pdf' "/>
    <dp:set-http-response-header name="'Content-Transfer-Encoding'" value="'binary' "/>
    <xsl:variable name="manifest" select="dp:variable('var://context/INPUT/attachment-manifest')"/>
    <xsl:variable name="pdf">
    <xsl:for-each select="$manifest/*/
    /">
    <xsl:variable name="filename" select="./uri/text()"/>
    <xsl:variable name="cid" select="concat($filename,'?Encode=base64')"/>
    <xsl:variable name="base64">
    <dp:url-open target="{$cid}"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">****(base64)****: <xsl:value-of select="$base64"/>
    </xsl:message>
    <xsl:variable name="raw" select="dp:binary-decode($base64)"/>
    <xsl:message dp:priority="debug">****(raw)****: <xsl:value-of select="$raw"/>
    </xsl:message>
    <xsl:value-of select="$raw"/>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="$pdf"/>
    </xsl:template>
    </xsl:stylesheet>
    Hello,

    > ...
    > The following XSLT returns only half of the entire PDF/binary
    > content. ...
    > Not sure at this point what could be wrong. I need to return the pdf.
    >

    please read section "Termination at first 0x00 byte" in my previous posting.
    Whenever a 0x00 byte gets introduced somehow in the data (0x00 of &​#0; is not a valid XML character,
    can only be introduced by the $raw trick from above posting) the first occurence is interpreted as end of data as described in that section.

    Please take this PDF document as a sample:
    http://publib.boulder.ibm.com/infocenter/wsdatap/v3r8m1/topic/xi50/optimizingThroughStreaming.pdf

    It contains many 0x00 bytes, the first one at offset 2395:
    
    $ head --bytes 2400 optimizingThroughStreaming.pdf | od -tcx1 | tail -7 0004460   h       1   5   4       0       R       >   >      \r   s   t 68 20 31 35 34 20 30 20 52 20 3e 3e 20 0d 73 74 0004500   r   e   a   m  \r  \n   H 211   b   `   `   `   f   ` 340   x 72 65 61 6d 0d 0a 48 89 62 60 60 60 66 60 e0 78 0004520 303 300 016   $ 347   2  \b   0     200  \0 003   +   P 224 205 c3 c0 0e 24 e7 32 08 30 20 80 00 03 2b 50 94 85 0004540 $
    


    This setting of Content-Type matches what you state above -- return one PDF file:
    
    ... <xsl:template match=
    "/"> <dp:set-http-response-header name=
    "'Content-Type'" value=
    "'application/pdf' "/> <dp:set-http-response-header name=
    "'Content-Transfer-Encoding'" value=
    "'binary' "/>
    


    But here you iterate over all attachments and just copy them together for the output.
    Are you sure that just copying all attachments will result in a valid PDF file?!?
    
    <xsl:for-each select=
    "$manifest/*/ /
    "> <xsl:variable name=
    "filename" select=
    "./uri/text()"/> <xsl:variable name=
    "cid" select=
    "concat($filename,'?Encode=base64')"/> <xsl:variable name=
    "base64"> <dp:url-open target=
    "{$cid}"/> </xsl:variable> <xsl:message dp:priority=
    "debug">****(base64)****: <xsl:value-of select=
    "$base64"/> </xsl:message> <xsl:variable name=
    "raw" select=
    "dp:binary-decode($base64)"/> <xsl:message dp:priority=
    "debug">****(raw)****: <xsl:value-of select=
    "$raw"/> </xsl:message> <xsl:value-of select=
    "$raw"/> </xsl:for-each>
    


    As said above, '<xsl:value-of select="$pdf"/>' will stop output at first 0x00 byte:
    
    <xsl:variable name=
    "manifest" select=
    "dp:variable('var://context/INPUT/attachment-manifest')"/> <xsl:variable name=
    "pdf"> ... </xsl:variable> <xsl:value-of select=
    "$pdf"/> </xsl:template> </xsl:stylesheet>
    


    Please see stylesheet "zero.xsl" in above posting on how to do the output you want to do (complete).

     
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-06-11T07:17:41Z  
    > These are the steps to get the value of a binary node,
    > *access it by ".../child::node()"
    > *then dp:binary-encode() it
    > *and then use dp:value-base64()
    like this:
    > ...

    there is a simpler and more efficient way to get the value of a binary node with validation for UTF-8:
    have dp:decode(_,'base-64') as 3rd step !
  • Jaango
    Jaango
    267 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-08T11:12:31Z  
    • HermannSW
    • ‏2011-06-11T07:17:41Z
    > These are the steps to get the value of a binary node,
    > *access it by ".../child::node()"
    > *then dp:binary-encode() it
    > *and then use dp:value-base64()
    like this:
    > ...

    there is a simpler and more efficient way to get the value of a binary node with validation for UTF-8:
    have dp:decode(_,'base-64') as 3rd step !
    Hi Hermann,
    Recently we had to play around with binary data.:).

    Is there a way i can preserve the input binary to output. The attached is my input.txt. However the generated output doesnt have the input characters as it is. At the end there are @ characters(4 in output and 5 in input at the end). I have used dp:value-base64() as the third step. If I use dp:decode(_,'base-64') as the third step, getting "Transforming (possibly binary) INPUT with xsl results stored in OUTPUT' failed: Valid base64 passed to dp:decode resulted in non UTF8: "

    Attached here with is the inputfile. Here is the xsl file, same as base-64.xsl.

    
    # java coproc2 value-base64.xsl input.txt http:
    //dp:server:2224; echo DŽׇţיքمذเ@řٖـ&#3 41;Ö䕣řń@@ǵ㠙ţ䙕`Öą@~@&#20 3830;@ԁトɕǀDŽ♀ŕ㙨@Ֆ〆&#14 44;Մ@Ɩـ@DŽׇţיքمذ&# 265264;῀@@@@
    


    Here is the xsl file

    
    <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <xsl:output omit-xml-declaration=
    "yes" />   <xsl:include href=
    "local:///binaryNode.xsl"/>   <dp:input-mapping   href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:template match=
    "/"> <xsl:value-of select=
    "dp:value-base64( dp:binary-encode(/object/message/child::node()))
    "/> </xsl:template> </xsl:stylesheet>
    
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T00:10:39Z  
    • Jaango
    • ‏2011-12-08T11:12:31Z
    Hi Hermann,
    Recently we had to play around with binary data.:).

    Is there a way i can preserve the input binary to output. The attached is my input.txt. However the generated output doesnt have the input characters as it is. At the end there are @ characters(4 in output and 5 in input at the end). I have used dp:value-base64() as the third step. If I use dp:decode(_,'base-64') as the third step, getting "Transforming (possibly binary) INPUT with xsl results stored in OUTPUT' failed: Valid base64 passed to dp:decode resulted in non UTF8: "

    Attached here with is the inputfile. Here is the xsl file, same as base-64.xsl.

    <pre class="jive-pre"> # java coproc2 value-base64.xsl input.txt http: //dp:server:2224; echo DŽׇţיքمذเ@řٖـ&#3 41;Ö䕣řń@@ǵ㠙ţ䙕`Öą@~@&#20 3830;@ԁトɕǀDŽ♀ŕ㙨@Ֆ〆&#14 44;Մ@Ɩـ@DŽׇţיքمذ&# 265264;῀@@@@ </pre>

    Here is the xsl file

    <pre class="jive-pre"> <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" > <xsl:output omit-xml-declaration= "yes" /> <xsl:include href= "local:///binaryNode.xsl"/> <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:template match= "/"> <xsl:value-of select= "dp:value-base64( dp:binary-encode(/object/message/child::node())) "/> </xsl:template> </xsl:stylesheet> </pre>
    Hi Maneesh,

    it is good that you ask in this thread.

    In October I gave two complete webcasts on Non-XML data processing and forgot to add the references here.
    The webcasts contain the presentation .pdf, the recording .mp3 as well as a .zip containing all sample stylesheets and files.

    Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (1/2) - Basics and Encodings
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977

    Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (2/2) - Advanced
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

     
    Related to this current thread, you may find details on DataPower XML node type extension binaryNode on this slide:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=8

    And the answer to your question, how to output binary data unchanged, is by using a dp:output-mapping, see this slide for a complete example:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

    Please see also slide "Return GIF image for Browser display" on how to retrieve binary data via <dp:url-open ...>
    (animated .gif file from my website in the sample stylesheet) and output it unchanged by dp:output-mapping:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

     
    If you do not need to deal with encoding conversions, then you may use these two slides as DataPower Non-XML cheat sheet :-)
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=13
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=5

     
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T00:12:39Z  
    • HermannSW
    • ‏2011-12-09T00:10:39Z
    Hi Maneesh,

    it is good that you ask in this thread.

    In October I gave two complete webcasts on Non-XML data processing and forgot to add the references here.
    The webcasts contain the presentation .pdf, the recording .mp3 as well as a .zip containing all sample stylesheets and files.

    Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (1/2) - Basics and Encodings
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977

    Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (2/2) - Advanced
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

     
    Related to this current thread, you may find details on DataPower XML node type extension binaryNode on this slide:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=8

    And the answer to your question, how to output binary data unchanged, is by using a dp:output-mapping, see this slide for a complete example:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

    Please see also slide "Return GIF image for Browser display" on how to retrieve binary data via <dp:url-open ...>
    (animated .gif file from my website in the sample stylesheet) and output it unchanged by dp:output-mapping:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

     
    If you do not need to deal with encoding conversions, then you may use these two slides as DataPower Non-XML cheat sheet :-)
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=13
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=5

     
    Hermann<myXsltBlog/>
    Ups, sent too quick, the "Return GIF image for Browser display" link is wrong, here is the correct one:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=3#page=18

    Hermann.
  • Jaango
    Jaango
    267 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T06:41:50Z  
    • HermannSW
    • ‏2011-12-09T00:12:39Z
    Ups, sent too quick, the "Return GIF image for Browser display" link is wrong, here is the correct one:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=3#page=18

    Hermann.
    Perfect,
    Thanks Hermann
  • Jaango
    Jaango
    267 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T12:06:22Z  
    • Jaango
    • ‏2011-12-09T06:41:50Z
    Perfect,
    Thanks Hermann
    Hermann,
    I was able to generate the ouput, like the way you explained. However, if I use the below xsl to store the binary contents in a file, under temp(again by your guidance in another post), getting
    *****binary node**** as the contents of file.

    Is this possible, to generate the text file with the actual contents of the input. As always your guidance helps a lot

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp"
    >
      <xsl:output omit-xml-declaration="yes"/>
      <dp:input-mapping href="local:///binaryNode.ffd" type="ffd"/>
      <dp:output-mapping href="local:///binaryNode.ffd" type="ffd"/>
     
        <xsl:template match="/">
          <object>
            <message>
              <dp:dump-nodes file="'abc.txt'" nodes="/object/message/node()"/>
              <dp:url-open target="temporary:///abc.txt"/>
            </message>
          </object>
        </xsl:template>
    </xsl:stylesheet>
    
    Updated on 2014-03-25T03:05:45Z at 2014-03-25T03:05:45Z by iron-man
  • Liv2luv
    Liv2luv
    573 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T14:49:36Z  
    • Jaango
    • ‏2011-12-09T12:06:22Z
    Hermann,
    I was able to generate the ouput, like the way you explained. However, if I use the below xsl to store the binary contents in a file, under temp(again by your guidance in another post), getting
    *****binary node**** as the contents of file.

    Is this possible, to generate the text file with the actual contents of the input. As always your guidance helps a lot

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" > <xsl:output omit-xml-declaration="yes"/> <dp:input-mapping href="local:///binaryNode.ffd" type="ffd"/> <dp:output-mapping href="local:///binaryNode.ffd" type="ffd"/> <xsl:template match="/"> <object> <message> <dp:dump-nodes file="'abc.txt'" nodes="/object/message/node()"/> <dp:url-open target="temporary:///abc.txt"/> </message> </object> </xsl:template> </xsl:stylesheet> </pre>
    dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.

    Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:

    <xsl:variable name="someText"
          select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>
              
     <xsl:variable name="nodeSet">
             <x>
                    <xsl:copy-of select="$someText"/>
             </x>
     </xsl:variable>
     
    <dp:dump-nodes file="'someFile.txt'" nodes="$nodeSet" />
    


    Finally, dp:output-mapping is not needed in this case.
    Updated on 2014-03-25T03:05:41Z at 2014-03-25T03:05:41Z by iron-man
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-09T18:59:20Z  
    • Liv2luv
    • ‏2011-12-09T14:49:36Z
    dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.

    Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:variable name="someText" select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/> <xsl:variable name="nodeSet"> <x> <xsl:copy-of select="$someText"/> </x> </xsl:variable> <dp:dump-nodes file="'someFile.txt'" nodes="$nodeSet" /> </pre>

    Finally, dp:output-mapping is not needed in this case.
    > Liv2luv wrote:
    > dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.
    >
    Maneesh said "Is there a way i can preserve the input binary to output".
    He wants to dump the data AND pass it unmodified.
    So the dp:url-open is needed.

    > Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:
    >
    >
    
    > >  <xsl:variable name=
    "someText" >       select=
    "dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/> > >  <xsl:variable name=
    "nodeSet"> >         <x> >                 <xsl:copy-of select=
    "$someText"/> >          </x> >  </xsl:variable> > > <dp:dump-nodes file=
    "'someFile.txt'" nodes=
    "$nodeSet" /> >
    

    >
    > Finally, dp:output-mapping is not needed in this case.
    >
    again, it is needed as he wants to pass data back.

    Also Maneesh's data seems to be binary data, not UTF-8 encoded text.
    So dp:decode() as used in your sample will complain on Non-UTF8 data.

    What I think Maneesh wants is dump-nodes.xsl below.
    It does an identity copy of his backend response data to the client.
    In addition, it dumps the binary data base64 encoded in temporary folder.

    This is a simple demo only.
    What is missing is incorporation transaction ID into dump file name,
    otherwise each transaction just overwrites the previous dump.
    AND being careful to make sure not running out of temp space.
    This should be used for development or debugging situations only.
    
    [stammw@oc4482023428 xslt]$ od -tcx1 te0t 0000000   t   e  \0   t 74  65  00  74 0000004 [stammw@oc4482023428 xslt]$ coproc2 dump-nodes.xsl te0t http:
    //dp5-l3:2224; echo tet [stammw@oc4482023428 xslt]$   (downloaded 
    'abc.txt' from temporary: folder)   [stammw@oc4482023428 xslt]$ cat abc.txt; echo <b64>dGUAdA==</b64> [stammw@oc4482023428 xslt]$ cat dump-nodes.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/> <dp:output-mapping href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/>   <xsl:template match=
    "/"> <object> <message> <!-- create a node set 
    
    for dump-nodes, data base64 encoded --> <xsl:variable name=
    "dump"> <b64><xsl:value-of select=
    "$input64"/></b64> </xsl:variable>   <!-- dump it --> <dp:dump-nodes file=
    "'abc.txt'" nodes=
    "$dump"/>   <!-- 
    "binary" identity transform --> <xsl:copy-of select=
    "dp:binary-decode($input64)"/> </message> </object> </xsl:template> </xsl:stylesheet> [stammw@oc4482023428 xslt]$
    


     
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-10T17:38:17Z  
    • HermannSW
    • ‏2011-12-09T18:59:20Z
    > Liv2luv wrote:
    > dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.
    >
    Maneesh said "Is there a way i can preserve the input binary to output".
    He wants to dump the data AND pass it unmodified.
    So the dp:url-open is needed.

    > Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:
    >
    > <pre class="jive-pre"> > > <xsl:variable name= "someText" > select= "dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/> > > <xsl:variable name= "nodeSet"> > <x> > <xsl:copy-of select= "$someText"/> > </x> > </xsl:variable> > > <dp:dump-nodes file= "'someFile.txt'" nodes= "$nodeSet" /> > </pre>
    >
    > Finally, dp:output-mapping is not needed in this case.
    >
    again, it is needed as he wants to pass data back.

    Also Maneesh's data seems to be binary data, not UTF-8 encoded text.
    So dp:decode() as used in your sample will complain on Non-UTF8 data.

    What I think Maneesh wants is dump-nodes.xsl below.
    It does an identity copy of his backend response data to the client.
    In addition, it dumps the binary data base64 encoded in temporary folder.

    This is a simple demo only.
    What is missing is incorporation transaction ID into dump file name,
    otherwise each transaction just overwrites the previous dump.
    AND being careful to make sure not running out of temp space.
    This should be used for development or debugging situations only.
    <pre class="jive-pre"> [stammw@oc4482023428 xslt]$ od -tcx1 te0t 0000000 t e \0 t 74 65 00 74 0000004 [stammw@oc4482023428 xslt]$ coproc2 dump-nodes.xsl te0t http: //dp5-l3:2224; echo tet [stammw@oc4482023428 xslt]$ (downloaded 'abc.txt' from temporary: folder) [stammw@oc4482023428 xslt]$ cat abc.txt; echo <b64>dGUAdA==</b64> [stammw@oc4482023428 xslt]$ cat dump-nodes.xsl <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" > <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <dp:output-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:variable name= "input64" select= "dp:binary-encode(/object/message/node())"/> <xsl:template match= "/"> <object> <message> <!-- create a node set for dump-nodes, data base64 encoded --> <xsl:variable name= "dump"> <b64><xsl:value-of select= "$input64"/></b64> </xsl:variable> <!-- dump it --> <dp:dump-nodes file= "'abc.txt'" nodes= "$dump"/> <!-- "binary" identity transform --> <xsl:copy-of select= "dp:binary-decode($input64)"/> </message> </object> </xsl:template> </xsl:stylesheet> [stammw@oc4482023428 xslt]$ </pre>

     
    Hermann<myXsltBlog/>
    This is nicer:
    <xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions" 
      extension-element-prefixes="dp"
    >
      <dp:input-mapping  href="store:///pkcs7-convert-input.ffd" type="ffd"/>
      <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
     
     
      <xsl:variable name="input64" 
        select="dp:binary-encode(/object/message/node())"/>
     
     
      <!-- create a node set for dump-nodes, binary data base64 encoded -->
      <xsl:variable name="dump">
        <b64><xsl:value-of select="$input64"/></b64>
      </xsl:variable>
     
      <!-- and dump it -->
      <dp:dump-nodes file="'abc.txt'" nodes="$dump"/>
     
     
      <xsl:template match="/"> 
     
        <!-- "binary" identity transform -->
        <object>
          <message>
            <xsl:copy-of select="dp:binary-decode($input64)"/>
          </message>
        </object>
      </xsl:template>
    </xsl:stylesheet>
    


    Hermann.
    Updated on 2014-03-25T03:05:37Z at 2014-03-25T03:05:37Z by iron-man
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-11T00:40:30Z  
    • HermannSW
    • ‏2011-12-10T17:38:17Z
    This is nicer:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" > <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/> <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/> <xsl:variable name="input64" select="dp:binary-encode(/object/message/node())"/> <!-- create a node set for dump-nodes, binary data base64 encoded --> <xsl:variable name="dump"> <b64><xsl:value-of select="$input64"/></b64> </xsl:variable> <!-- and dump it --> <dp:dump-nodes file="'abc.txt'" nodes="$dump"/> <xsl:template match="/"> <!-- "binary" identity transform --> <object> <message> <xsl:copy-of select="dp:binary-decode($input64)"/> </message> </object> </xsl:template> </xsl:stylesheet> </pre>

    Hermann.
    Sorry, I should have tested the 2nd stylesheet.
    It is nicer but does not work (does not dump).

    This is nicer and works:
    
    $ cat dump-nodes.3.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/> <dp:output-mapping href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/> <!-- create a node set 
    
    for dump-nodes, binary data base64 encoded --> <xsl:variable name=
    "dump"> <b64><xsl:value-of select=
    "$input64"/></b64> </xsl:variable> <xsl:template match=
    "/"> <!-- and dump it --> <dp:dump-nodes file=
    "'abc.txt'" nodes=
    "$dump"/> <!-- 
    "binary" identity transform --> <object> <message> <xsl:copy-of select=
    "dp:binary-decode($input64)"/> </message> </object> </xsl:template>   </xsl:stylesheet>   $
    


     
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-12-12T09:01:16Z  
    • HermannSW
    • ‏2011-12-11T00:40:30Z
    Sorry, I should have tested the 2nd stylesheet.
    It is nicer but does not work (does not dump).

    This is nicer and works:
    <pre class="jive-pre"> $ cat dump-nodes.3.xsl <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" > <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <dp:output-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:variable name= "input64" select= "dp:binary-encode(/object/message/node())"/> <!-- create a node set for dump-nodes, binary data base64 encoded --> <xsl:variable name= "dump"> <b64><xsl:value-of select= "$input64"/></b64> </xsl:variable> <xsl:template match= "/"> <!-- and dump it --> <dp:dump-nodes file= "'abc.txt'" nodes= "$dump"/> <!-- "binary" identity transform --> <object> <message> <xsl:copy-of select= "dp:binary-decode($input64)"/> </message> </object> </xsl:template> </xsl:stylesheet> $ </pre>

     
    Hermann<myXsltBlog/>
    Suresh and Hermann,

    Thanks for your inputs and solutions :)
  • Jaango
    Jaango
    267 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-02-22T10:49:47Z  
    • Jaango
    • ‏2011-12-12T09:01:16Z
    Suresh and Hermann,

    Thanks for your inputs and solutions :)
    Hi Hermann,

    I have a context variable with binary value set. Just wanted to print in my logs. However the below code does not seem to work

    <xsl:message dp:priority="error">
      Test: 
      <xsl:copy-of select="dp:binary-encode(dp:variable('var://context/MyBinaryvalue'))" /> 
      </xsl:message>
    


    The error is

    "Cannot convert this value to binary data" and the xsl, where the above code is there, fails
    Updated on 2014-03-25T03:02:08Z at 2014-03-25T03:02:08Z by iron-man
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-02-23T15:36:22Z  
    • Jaango
    • ‏2012-02-22T10:49:47Z
    Hi Hermann,

    I have a context variable with binary value set. Just wanted to print in my logs. However the below code does not seem to work

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:message dp:priority="error"> Test: <xsl:copy-of select="dp:binary-encode(dp:variable('var://context/MyBinaryvalue'))" /> </xsl:message> </pre>

    The error is

    "Cannot convert this value to binary data" and the xsl, where the above code is there, fails
    Hi,
    >
    > I have a context variable with binary value set. Just wanted to print in my logs. However the below code does not seem to work
    >
    >
    
    > <xsl:message dp:priority=
    "error"> >   Test: >   <xsl:copy-of select=
    "dp:binary-encode(dp:variable('var://context/MyBinaryvalue'))" /> >   </xsl:message> >
    

    >
    > The error is
    >
    > "Cannot convert this value to binary data" and the xsl, where the above code is there, fails
    >
    sorry, binary contexts are different, their binary content cannot be accessed that way.

    For logging above you did choose dp:binary-encode() which is fine.

    You can do what you want in a binary transform action like toBase64b.xsl.
    I tested this and it works, Input context of binary transform actions is "MyBinaryvalue":
    
    $ cat toBase64b.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:copy-of select=
    "dp:binary-encode(/object/message/node())"/> </xsl:template> </xsl:stylesheet> $
    

    Hermann<myXsltBlog/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-04T09:46:53Z  
    Hi Hermann,

    I am just trying to output the string representation of response .

    Below is my xsl

    <xsl:stylesheet version="1.0" extension-element-prefixes="dp"
    exclude-result-prefixes="dp dpconfig date" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions" xmlns:date="http://exslt.org/dates-and-times"
    xmlns:dpconfig="http://www.datapower.com/param/config">

    <dp:output-mapping href="local:///simple.ffd" type="ffd"/>
    <xsl:template match="/">

    <xsl:variable name="resp">
    <dp:url-open target="http://http-server-ip:port/test-text-file" response="binaryNode"/>
    </xsl:variable>
    <MyFile>
    <Payload><xsl:value-of select="$resp/result/binary/child::node()"/></Payload>
    </MyFile>

    </xsl:template>
    </xsl:stylesheet>

    • FFD FIle****
    <File version="1.0" name="MyFile">
    <Field name="Payload" minOccurs="1" type="String"/>
    </File>
    *************

    Above code is giving me blank output

    Now if i use

    <xsl:variable name="base64">
    <xsl:value-of select="dp:binary-encode($resp/result/binary/child::node())"/>
    </xsl:variable>

    <xsl:variable name="raw" select="dp:decode($base64,'base-64')"/>

    and then use value-of $raw It works fine.
    • Another weird thing is happening is that if use <xsl:value-of select="$resp/result/binary/child::node()"/> line of code before encode and decode , Then even after encode and decode my Result is blank.

    Could you please suggest , I just some how wanted to skip encode n decode , and want to use the string representaion of binaryData
    Thanks
    Pradeep
  • Liv2luv
    Liv2luv
    573 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-04T11:27:39Z  
    Hi Hermann,

    I am just trying to output the string representation of response .

    Below is my xsl

    <xsl:stylesheet version="1.0" extension-element-prefixes="dp"
    exclude-result-prefixes="dp dpconfig date" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions" xmlns:date="http://exslt.org/dates-and-times"
    xmlns:dpconfig="http://www.datapower.com/param/config">

    <dp:output-mapping href="local:///simple.ffd" type="ffd"/>
    <xsl:template match="/">

    <xsl:variable name="resp">
    <dp:url-open target="http://http-server-ip:port/test-text-file" response="binaryNode"/>
    </xsl:variable>
    <MyFile>
    <Payload><xsl:value-of select="$resp/result/binary/child::node()"/></Payload>
    </MyFile>

    </xsl:template>
    </xsl:stylesheet>

    • FFD FIle****
    <File version="1.0" name="MyFile">
    <Field name="Payload" minOccurs="1" type="String"/>
    </File>
    *************

    Above code is giving me blank output

    Now if i use

    <xsl:variable name="base64">
    <xsl:value-of select="dp:binary-encode($resp/result/binary/child::node())"/>
    </xsl:variable>

    <xsl:variable name="raw" select="dp:decode($base64,'base-64')"/>

    and then use value-of $raw It works fine.
    • Another weird thing is happening is that if use <xsl:value-of select="$resp/result/binary/child::node()"/> line of code before encode and decode , Then even after encode and decode my Result is blank.

    Could you please suggest , I just some how wanted to skip encode n decode , and want to use the string representaion of binaryData
    Thanks
    Pradeep
    First in the XSL:

    it is input-mapping instead of output-mapping

    FFD file looks like:

    <?xml version="1.0" encoding="UTF-8" ?>
    <File version="2.1" name="MyFile">
    <Field name="Payload" type="String" />
    </File>
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-07T13:40:48Z  
    • Liv2luv
    • ‏2012-05-04T11:27:39Z
    First in the XSL:

    it is input-mapping instead of output-mapping

    FFD file looks like:

    <?xml version="1.0" encoding="UTF-8" ?>
    <File version="2.1" name="MyFile">
    <Field name="Payload" type="String" />
    </File>
    > First in the XSL:
    >
    > it is input-mapping instead of output-mapping
    >
    Hi Suresh, it is output-mapping since he wants to output text data received by dp:url-open (binaryNode).
    Pradeep, please see "getgif.xsl" on slide 18 of this WSTE webcast (you do not need your own FFD as long as your test-text-file is UTF-8 encoded):
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    You can find all sample files in "Samples File" attachment.
    Just try out "getgif.xsl" as it is -- it will get you a small animated .gif file from my private web server ...

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-08T03:48:59Z  
    • Liv2luv
    • ‏2012-05-04T11:27:39Z
    First in the XSL:

    it is input-mapping instead of output-mapping

    FFD file looks like:

    <?xml version="1.0" encoding="UTF-8" ?>
    <File version="2.1" name="MyFile">
    <Field name="Payload" type="String" />
    </File>
    Hi ,

    As my input to the Transform Action is a XML , therefore i am not using input mapping.

    I only want to send the non-xml data back to the client/Backend
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-08T06:41:14Z  
    • HermannSW
    • ‏2012-05-07T13:40:48Z
    > First in the XSL:
    >
    > it is input-mapping instead of output-mapping
    >
    Hi Suresh, it is output-mapping since he wants to output text data received by dp:url-open (binaryNode).
    Pradeep, please see "getgif.xsl" on slide 18 of this WSTE webcast (you do not need your own FFD as long as your test-text-file is UTF-8 encoded):
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    You can find all sample files in "Samples File" attachment.
    Just try out "getgif.xsl" as it is -- it will get you a small animated .gif file from my private web server ...

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    Hi Hermann,

    Thanks a lot for your Inputs.

    I tried and it is working as expected.

    But my requirement is slightly different. i need to add to string fields at the end of text file and the concatenated string should go to the backend server

    Content of test-text-file is
    hello world

    trail1 ="string1" and trail2="string2"

    Final output would be hello world string1 string2
    As i am unable to hold the binary output into xsl variable therefore i am unable to achieve this string concatenation.

    But if i do dp:binary-encode and dp:decode then xsl variable is holding the content of test-text-file.
    My only objective is skip the encode and decode because my file is already having UTF-8 encoded content.

    I believe , i am still missing some thing in binaryNode as i am getting some weird outputs ( If i use simple.ffd)

    Could you please provide your inputs on this.

    Thanks
    Pradeep
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-08T10:41:02Z  
    Hi Pradeep,

    > But if i do dp:binary-encode and dp:decode then xsl variable is holding the content of test-text-file.
    that is correct.

    > My only objective is skip the encode and decode because my file is already having UTF-8 encoded content.
    You cannot, because you need to convert the "binaryNode" response you get to String.

    AND you should not, because the decode does UTF-8 validation for you, see slide 16 of this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977

    You should not rely on that someone promises to send UTF-8 data -- such a contract will always fail at some point in time.
    See slide 5 of this webcast what can go wrong if you do not validate:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    And that is not the worst what can happen.
    Regarding your requirement of appending strings to what you read, please see binary-append.xsl posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/binary_append_xsl7

    It demonstrates how to append arbitrary binary data, but of course you can do the same with text strings.
    In your case you can use this approach of getting yout trail strings appended:
    
    ... <xsl:variable name=
    "str" select=
    "dp:decode(dp:binary-encode($resp/result/binary/node()),'base-64')"/> ... <object> <message> <xsl:copy-of select=
    "dp:binary-decode(dp:encode(concat($str,$trail1,$trail2),'base-64'))"/> </message> </object> ...
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-08T17:24:48Z  
    • HermannSW
    • ‏2012-05-08T10:41:02Z
    Hi Pradeep,

    > But if i do dp:binary-encode and dp:decode then xsl variable is holding the content of test-text-file.
    that is correct.

    > My only objective is skip the encode and decode because my file is already having UTF-8 encoded content.
    You cannot, because you need to convert the "binaryNode" response you get to String.

    AND you should not, because the decode does UTF-8 validation for you, see slide 16 of this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977

    You should not rely on that someone promises to send UTF-8 data -- such a contract will always fail at some point in time.
    See slide 5 of this webcast what can go wrong if you do not validate:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    And that is not the worst what can happen.
    Regarding your requirement of appending strings to what you read, please see binary-append.xsl posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/binary_append_xsl7

    It demonstrates how to append arbitrary binary data, but of course you can do the same with text strings.
    In your case you can use this approach of getting yout trail strings appended:
    <pre class="jive-pre"> ... <xsl:variable name= "str" select= "dp:decode(dp:binary-encode($resp/result/binary/node()),'base-64')"/> ... <object> <message> <xsl:copy-of select= "dp:binary-decode(dp:encode(concat($str,$trail1,$trail2),'base-64'))"/> </message> </object> ... </pre>

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    Thanks a lot Hermann for your Inputs.

    I got this working now.
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-07-27T07:58:28Z  
    A colleague needed to use "dp:validate-hex()" and found a problem end of June.
    I fixed that, sent the fixed version to him -- and forgot to update this thread.

    Yesterday another colleague did run into the same -- this time I do the update.

    The problem is that I mistakenly used a <xsl:variable> instead of a <xsl:param> in <func:function name="dp:validate-hex"> ...
    (if you want to use that function, please correct)

    $ diff -C1 binaryNode.xsl.old binaryNode.xsl
    *** binaryNode.xsl.old  2012-06-28 14:40:02.000000000 +0200
    --- binaryNode.xsl      2012-06-28 14:41:34.000000000 +0200
    ***************
    *** 65,67 ****
        <func:function name="dp:validate-hex">
    !     <xsl:variable name="hexString" />
      
    --- 65,67 ----
        <func:function name="dp:validate-hex">
    !     <xsl:param name="hexString" />
      
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:50:42Z at 2014-03-25T02:50:42Z by iron-man
  • HermannSW
    HermannSW
    4647 Posts

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-10-11T12:18:58Z  
    • HermannSW
    • ‏2012-07-27T07:58:28Z
    A colleague needed to use "dp:validate-hex()" and found a problem end of June.
    I fixed that, sent the fixed version to him -- and forgot to update this thread.

    Yesterday another colleague did run into the same -- this time I do the update.

    The problem is that I mistakenly used a <xsl:variable> instead of a <xsl:param> in <func:function name="dp:validate-hex"> ...
    (if you want to use that function, please correct)

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ diff -C1 binaryNode.xsl.old binaryNode.xsl *** binaryNode.xsl.old 2012-06-28 14:40:02.000000000 +0200 --- binaryNode.xsl 2012-06-28 14:41:34.000000000 +0200 *************** *** 65,67 **** <func:function name="dp:validate-hex"> ! <xsl:variable name="hexString" /> --- 65,67 ---- <func:function name="dp:validate-hex"> ! <xsl:param name="hexString" /> $ </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    There were still some function parameters declared as <xsl:variable> instead of <xsl:param> in some <func:function>s.
    Find attached the corrected stylesheet binaryNode.xsl.

    These are the functions provided ("dp:...")
    $ xpath++ "str:split(str:concat(//func:function/@name),'dp:')[.!='']" binaryNode.xsl 
    <token>normalize-hex</token><token>validate-hex</token><token>validate-base64</token><token>value</token><token>value-base64</token><token>value-hex</token>
    $
    


    More current information on binaryNode and Non-XML processing inside stylesheets can be found in these two webcasts:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:47:28Z at 2014-03-25T02:47:28Z by iron-man