Topic
  • 4 replies
  • Latest Post - ‏2012-11-06T02:50:59Z by Jaango
Jaango
Jaango
267 Posts

Pinned topic Ebdic encode hex values using xsls

‏2012-11-01T04:25:05Z |
I have the below input xml to the stylesheet, which i intended for outputting binary data in ebcdic.

input xml


<Root>12345</Root>


my stylesheet


<?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" omit-xml-declaration=
"yes" encoding=
"ebdic-de"/>   <xsl:template match=
"/"> <xsl:value-of select=
"."/> </xsl:template> </xsl:stylesheet>


however after this action If I put a non xml transform(I wanted to manipulate on the resulting ebcdic encoded hex values), I dont get anything in the output. Is it because the above stylesheet is not putting binary data. How to achieve this. My aim is to manipulate on the resulting ebcdic encoded hex values, then finally output the binary.
Here is my non xml transform, output of the above is the input to the below.


<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:template match=
"/"> <xsl:variable name=
"input64" select=
"dp:binary-encode(/object/message/node())"/> <xsl:variable name=
"hex" select=
"substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!--manipulation on hex happens and 

final hex is stored in the variable finalhex--> <xsl:variable name=
"finalhex" select=
"'f1f2f3'"/> <!--

for demo only--> <xsl:variable name=
"out64" select=
"dp:radix-convert($finalhex,64,16)"/> <object> <message> <xsl:copy-of select=
"dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet>
Updated on 2012-11-06T02:50:59Z at 2012-11-06T02:50:59Z by Jaango
  • HermannSW
    HermannSW
    4874 Posts

    Re: Ebdic encode hex values using xsls

    ‏2012-11-01T08:46:08Z  
    You have a typo in your encoding, which leads to warning "Unsupported encoding ebdic-de, using utf-8 instead".

    After correcting the encoding to "ebcdic-de" you get the output you want:
    $ coproc2 ebcdic.xsl input.xml http://dp3-l3:2223 -s | od -Ax -tcx1
    000000 361 362 363 364 365
            f1  f2  f3  f4  f5
    000005
    $
    


    Be aware that it is most likely that you have the wrong order of radices in your term "dp:radix-convert($finalhex,64,16)".
    This should work:
    <xsl:variable name="out64" select="dp:radix-convert($finalhex,16,64)"/>
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:46:28Z at 2014-03-25T02:46:28Z by iron-man
  • Jaango
    Jaango
    267 Posts

    Re: Ebdic encode hex values using xsls

    ‏2012-11-01T13:29:29Z  
    • HermannSW
    • ‏2012-11-01T08:46:08Z
    You have a typo in your encoding, which leads to warning "Unsupported encoding ebdic-de, using utf-8 instead".

    After correcting the encoding to "ebcdic-de" you get the output you want:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ coproc2 ebcdic.xsl input.xml http://dp3-l3:2223 -s | od -Ax -tcx1 000000 361 362 363 364 365 f1 f2 f3 f4 f5 000005 $ </pre>

    Be aware that it is most likely that you have the wrong order of radices in your term "dp:radix-convert($finalhex,64,16)".
    This should work:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:variable name="out64" select="dp:radix-convert($finalhex,16,64)"/> </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Thanks, Hermann. Yeah I was using ebcdic-de only. However the output of ebcdic.xsl, will it be xml? The reason I am asking because using input mapping =store-pkcs.....ffd", in a stylesheet immediately after the ebcdic.xsl, the input is coming as blank.

    My guess is that(i have to try anyways), the output of ebcdic.xsl might be xml, because of which the stylesheet using ffd input mapping is not able to get the binary input. Those two errors you have mentioned, happened while pasting it; a copy paste mistake.

    ebcdic.xsl

    
    <?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" omit-xml-declaration=
    "yes" encoding=
    "ebcdic-de"/> <xsl:template match=
    "/"> <xsl:value-of select=
    "."/> </xsl:template> </xsl:stylesheet>
    


    Ihe xslt that comes after ebcdic.xsl(corrected the dp:radix parameters)

    
    <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:template match=
    "/"> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/> <xsl:variable name=
    "hex" select=
    "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!--manipulation on hex happens and 
    
    final hex is stored in the variable finalhex--> <xsl:variable name=
    "finalhex" select=
    "'f1f2f3'"/> <!--
    
    for demo only--> <xsl:variable name=
    "out64" select=
    "dp:radix-convert($finalhex,16,64)"/> <object> <message> <xsl:copy-of select=
    "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet>
    


    I guess may be we should try accessing as xml, like the below stylesheet, to get the input hex in the variable, hex

    
    <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:template match=
    "/"> <xsl:variable name=
    "ebcdicstring" select=
    "."/> <xsl:variable name=
    "input64" select=
    "dp:encode($ebcdicstring,'base-64')"/> <xsl:variable name=
    "hex" select=
    "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!--manipulation on hex happens and 
    
    final hex is stored in the variable finalhex--> <xsl:variable name=
    "finalhex" select=
    "'f1f2f3'"/> <!--
    
    for demo only--> <xsl:variable name=
    "out64" select=
    "dp:radix-convert($finalhex,64,16)"/> <object> <message> <xsl:copy-of select=
    "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet>
    
  • HermannSW
    HermannSW
    4874 Posts

    Re: Ebdic encode hex values using xsls

    ‏2012-11-05T11:26:15Z  
    • Jaango
    • ‏2012-11-01T13:29:29Z
    Thanks, Hermann. Yeah I was using ebcdic-de only. However the output of ebcdic.xsl, will it be xml? The reason I am asking because using input mapping =store-pkcs.....ffd", in a stylesheet immediately after the ebcdic.xsl, the input is coming as blank.

    My guess is that(i have to try anyways), the output of ebcdic.xsl might be xml, because of which the stylesheet using ffd input mapping is not able to get the binary input. Those two errors you have mentioned, happened while pasting it; a copy paste mistake.

    ebcdic.xsl

    <pre class="jive-pre"> <?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" omit-xml-declaration= "yes" encoding= "ebcdic-de"/> <xsl:template match= "/"> <xsl:value-of select= "."/> </xsl:template> </xsl:stylesheet> </pre>

    Ihe xslt that comes after ebcdic.xsl(corrected the dp:radix parameters)

    <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"> <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <dp:output-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:template match= "/"> <xsl:variable name= "input64" select= "dp:binary-encode(/object/message/node())"/> <xsl:variable name= "hex" select= "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!--manipulation on hex happens and final hex is stored in the variable finalhex--> <xsl:variable name= "finalhex" select= "'f1f2f3'"/> <!-- for demo only--> <xsl:variable name= "out64" select= "dp:radix-convert($finalhex,16,64)"/> <object> <message> <xsl:copy-of select= "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet> </pre>

    I guess may be we should try accessing as xml, like the below stylesheet, to get the input hex in the variable, hex

    <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"> <!--<dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/>--> <dp:output-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:template match= "/"> <xsl:variable name= "ebcdicstring" select= "."/> <xsl:variable name= "input64" select= "dp:encode($ebcdicstring,'base-64')"/> <xsl:variable name= "hex" select= "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!--manipulation on hex happens and final hex is stored in the variable finalhex--> <xsl:variable name= "finalhex" select= "'f1f2f3'"/> <!-- for demo only--> <xsl:variable name= "out64" select= "dp:radix-convert($finalhex,64,16)"/> <object> <message> <xsl:copy-of select= "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet> </pre>
    Hi Maneesh,

    see my last posting, the output is just "12345" ebcdic-encoded, not any XML.
    So you do need the dp:input-mapping.

    You sample is confusing, why do you try to process the input into $hex variable,
    if your output is based on $finalhex which is in no way related to the input?

     
    Here is a complete example, and process-ebcdic.xsl is a Non-XML stylesheet just "framing" its input by "9" digits.
    Be aware that you have to use the Non-XML endpoint (port 2224) of coproc2 service for process-ebcdic.xsl:
    
    $ coproc2 ebcdic.xsl input.xml http:
    //dp3-l3:2223 -s | od -Ax -tcx1 000000 361 362 363 364 365 f1  f2  f3  f4  f5 000005 $ $ coproc2 ebcdic.xsl input.xml http:
    //dp3-l3:2223 -s > ebcdic.dat $ $ coproc2 process-ebcdic.xsl ebcdic.dat http:
    //dp3-l3:2224 -s | od -Ax -tcx1  000000 371 361 362 363 364 365 371 f9  f1  f2  f3  f4  f5  f9 000007 $ $ cat process-ebcdic.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:template match=
    "/"> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/> <xsl:variable name=
    "hex" select=
    "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!-- 
    
    for demo only, frame input by 
    "9" digits --> <xsl:variable name=
    "finalhex" select=
    "concat('f9', $hex, 'f9')"/> <xsl:variable name=
    "out64" select=
    "dp:radix-convert($finalhex,16,64)"/>   <object> <message> <xsl:copy-of select=
    "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet> $
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • Jaango
    Jaango
    267 Posts

    Re: Ebdic encode hex values using xsls

    ‏2012-11-06T02:50:59Z  
    • HermannSW
    • ‏2012-11-05T11:26:15Z
    Hi Maneesh,

    see my last posting, the output is just "12345" ebcdic-encoded, not any XML.
    So you do need the dp:input-mapping.

    You sample is confusing, why do you try to process the input into $hex variable,
    if your output is based on $finalhex which is in no way related to the input?

     
    Here is a complete example, and process-ebcdic.xsl is a Non-XML stylesheet just "framing" its input by "9" digits.
    Be aware that you have to use the Non-XML endpoint (port 2224) of coproc2 service for process-ebcdic.xsl:
    <pre class="jive-pre"> $ coproc2 ebcdic.xsl input.xml http: //dp3-l3:2223 -s | od -Ax -tcx1 000000 361 362 363 364 365 f1 f2 f3 f4 f5 000005 $ $ coproc2 ebcdic.xsl input.xml http: //dp3-l3:2223 -s > ebcdic.dat $ $ coproc2 process-ebcdic.xsl ebcdic.dat http: //dp3-l3:2224 -s | od -Ax -tcx1 000000 371 361 362 363 364 365 371 f9 f1 f2 f3 f4 f5 f9 000007 $ $ cat process-ebcdic.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:template match= "/"> <xsl:variable name= "input64" select= "dp:binary-encode(/object/message/node())"/> <xsl:variable name= "hex" select= "substring(dp:radix-convert(concat('8AAA',$input64),64,16),7)"/> <!-- for demo only, frame input by "9" digits --> <xsl:variable name= "finalhex" select= "concat('f9', $hex, 'f9')"/> <xsl:variable name= "out64" select= "dp:radix-convert($finalhex,16,64)"/> <object> <message> <xsl:copy-of select= "dp:binary-decode($out64)"/> </message> </object> </xsl:template> </xsl:stylesheet> $ </pre>

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    Thanks,Hermann. Yeah, i have tested and it works fine, there was a mistake in my xslt code.