Skip to main content

I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

I can help you in a couple hours.  In the meantime, please let me know what complaints Stylus Studio is making.  It would also help if you could post the JSON.

Back in a couple hours...


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Tom,

Thank You for your help.  Attached is the style sheet I have modified (renamed to .txt) as noted below.

I bring up json2xml_step1.xsl within Stylus Studio.

Error: "Parsing error at Ln 5 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','root','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'root','>')"/>

Error: "Parsing error at Ln 9 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/root','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/root','>')"/>

Error: "Parsing error at Ln 22 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','object','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'object','>')"/>

Error: "Parsing error at Ln 30 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/object','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/object','>')"/>

Error: "Parsing error at Ln 38 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','array','>')"/

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'array','>')"/>

Error: "Parsing error at Ln 46 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/array','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/array','>')"/>

Error: Parsing error at Ln 53 Col 34. whitespace expected

Change: <xsl:when test="$operandChar = '"'">

   To: <xsl:when test="$operandChar = "">, I dont' know if this was correct or not.

Error: Parsing error at Ln 59 Col 86. whitespace expected

Change: <xsl:variable name="nameString" select="substring-before(substring($remaining,2),'"')"/>

   To: <xsl:variable name="nameString" select="substring-before(substring($remaining,2),")"/>, I dont' know if this was correct or not.

Error: "Parsing error at Ln 61 Col 70.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','nameNode name="',$nameString,'"/>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'nameNode name="',$nameString,'"/>')"/>

Error: Parsing error at Ln 61 Col 89. whitespace expected

Change: <xsl:value-of disable-output-escaping="yes" select="concat(<,'nameNode name="',$nameString,'"/>')"/>

   To: ???, I don't know what to do here


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Tom,

Thank You for your help.  Attached is the style sheet I have modified (renamed to .txt) as noted below.

I bring up json2xml_step1.xsl within Stylus Studio.

Error: "Parsing error at Ln 5 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','root','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'root','>')"/>

Error: "Parsing error at Ln 9 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/root','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/root','>')"/>

Error: "Parsing error at Ln 22 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','object','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'object','>')"/>

Error: "Parsing error at Ln 30 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/object','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/object','>')"/>

Error: "Parsing error at Ln 38 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','array','>')"/

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'array','>')"/>

Error: "Parsing error at Ln 46 Col 62.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','/array','>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'/array','>')"/>

Error: Parsing error at Ln 53 Col 34. whitespace expected

Change: <xsl:when test="$operandChar = '"'">

   To: <xsl:when test="$operandChar = "">, I dont' know if this was correct or not.

Error: Parsing error at Ln 59 Col 86. whitespace expected

Change: <xsl:variable name="nameString" select="substring-before(substring($remaining,2),'"')"/>

   To: <xsl:variable name="nameString" select="substring-before(substring($remaining,2),")"/>, I dont' know if this was correct or not.

Error: "Parsing error at Ln 61 Col 70.  character cannot be used in attribute value 'select'; use < instead

Change: <xsl:value-of disable-output-escaping="yes" select="concat('<','nameNode name="',$nameString,'"/>')"/>

   To: <xsl:value-of disable-output-escaping="yes" select="concat(<,'nameNode name="',$nameString,'"/>')"/>

Error: Parsing error at Ln 61 Col 89. whitespace expected

Change: <xsl:value-of disable-output-escaping="yes" select="concat(<,'nameNode name="',$nameString,'"/>')"/>

   To: ???, I don't know what to do here


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Ok, I see what has happened.  Somewhere in the trips through the interweb the various entities for greater than, less than, etc. have been converted to the actual character.

Let me get the correct version placed somewhere where it is not trying to be rendered as HTML.  That will make a big difference.


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Ok, I have ZIPPED the two files into the attachment to this message.  See if that works better.

And thanks for the feedback.  I will go back to Tek-Tips to provide better information there.

Best regards,
Tom Morrison


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Tom,

Thank you very much.  Yes, the style sheets processed the JSON response into XML 100%.

Thanks,

Russell Haile


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

Tom,

Thank you very much.  Yes, the style sheets processed the JSON response into XML 100%.

Thanks,

Russell Haile


I’m currently working on a project for my manager where we need to interact with a JSON system.  I’m looking for a way to convert JSON into XML in order to process responses using a RM/Cobol application using XML-Extensions. 

After speaking with Steve Jolivet with Microfocus, a google search returned “Converting JSON to XML using XSLT 1.0” (link “www.tek-tips.com/viewthread.cfm written by Tom Morrison.  I copied Tom's two XSLT examples (json2xml_step1.xsl and json2xml_step2.xsl) into Stylus Studio X14 Professional.  I wanted to run the stylesheets over my existing JSON response in order to see the results. However, Stylus Studio complains about several things within json2xml_step1.xsl and I’m not strong enough in XSLT to determine what it's complaining about in some cases. 

Can anyone provide some insight, please?


#RMCOBOL
#XMLExtensions
#ConvertJSONtoXML

I wanted to provide some additional information, discovered as I was working with Russell on this.

My motivation to create a JSON to XML conversion using XML tooling was due to the need of a Micro Focus customer to process JSON responses from a well known payment system.  No free-standing JSON parser was available, and the application was already making heavy use of XML Extensions.  The rest of the story is in the Tek-Tips thread.  There are a couple caveats documented there as well.

As Russell stated in the original post, you may view the original Tek-Tips post here.  The XSLT posted in that forum succumbed to the a combination of HTML sharing various characteristics with XML, and my carelessness in checking the final result.  I have worked with the staff at Tek-Tips to get the posted XSLT corrected, but with only partial success.  Therefore, the ZIP file I posted here should be used.

Not stated anywhere in the Tek-Tips post is the fact that the input document is also a (very simple) XML document which encapsulates the JSON string.  One can infer this from the XSLT, but here is the format:

    <json-string>your JSON formatted text string here</json-string>

I can provide an RM/COBOL program to demonstrate the use of these XSLT stylesheets