JSON to XML with XSL fails in Oxygen but works online
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 2
- Joined: Fri Oct 29, 2021 12:51 pm
JSON to XML with XSL fails in Oxygen but works online
Hi
I'm trying to set up a transformation in the Oxygen editor to convert JSON files into DITA topics, but my XSL keeps failing in the Oxygen editor with the error:
In the Oxygen editor, I tried using the JSON content as a variable in the XSL to avoid input file issues, but when the XSL is run the error occurs. I also tried with files with various formats, and without BOM, but nothing's worked.
I've seen in online threads that there's something in the Oxygen editor that might be causing this.
Can someone help?
Regards,
Ian
I'm trying to set up a transformation in the Oxygen editor to convert JSON files into DITA topics, but my XSL keeps failing in the Oxygen editor with the error:
However, the online JSON->XML conversion worked at https://www.oxygenxml.com/xml_json_converter.htmlSXXP0003: Content is not allowed in prolog.
In the Oxygen editor, I tried using the JSON content as a variable in the XSL to avoid input file issues, but when the XSL is run the error occurs. I also tried with files with various formats, and without BOM, but nothing's worked.
I've seen in online threads that there's something in the Oxygen editor that might be causing this.
Can someone help?
Regards,
Ian
json-xsl-test-files.zip
You do not have the required permissions to view the files attached to this post.
-
- Posts: 2
- Joined: Fri Oct 29, 2021 12:51 pm
Re: JSON to XML with XSL fails in Oxygen but works online
Update...
After more time banging my head against the wall, I made some progress.
1) Wrap the JSON with an XML element, eg <data>
2) In the XSL, make the initial template to match the XML element; eg: (first successful test)
<xsl:template match="data">
<xsl:copy-of select="json-to-xml(.)"/>
</xsl:template>
This output the XML:
So now I have an XML file of array and map elements, I can hopefully take the next step toward DITA. (fingers crossed!)
After more time banging my head against the wall, I made some progress.
1) Wrap the JSON with an XML element, eg <data>
Code: Select all
<data>[
{
"name": "org",
"order": 1,
"displayName": "Organization"
},
{
"name": "usr",
"order": 2,
"displayName": "User"
},
{
"name": "zeb",
"order": 3,
"displayName": "Zebra"
}
]
</data>
<xsl:template match="data">
<xsl:copy-of select="json-to-xml(.)"/>
</xsl:template>
This output the XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<array xmlns="http://www.w3.org/2005/xpath-functions">
<map>
<string key="name">org</string>
<number key="order">1</number>
<string key="displayName">Organization</string>
</map>
<map>
<string key="name">usr</string>
<number key="order">2</number>
<string key="displayName">User</string>
</map>
<map>
<string key="name">zeb</string>
<number key="order">3</number>
<string key="displayName">Zebra</string>
</map>
</array>
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: JSON to XML with XSL fails in Oxygen but works online
Hello Ian,
The json-to-xml() function parameter must be the JSON file content. When you load a JSON file content you need to use the unparsed-text() function. Something like this
You can find an example of XSL file that converts JSON to XML in our samples folder [OxygenInstallDir]/samples/json/transform/json-to-xml.xsl
There is also a webinar and a vide demo that shows how to convert JSON to XML using XSLT:
https://www.oxygenxml.com/demo/json_query.html
https://youtu.be/wRgvWEKo6_w?t=2374
Best Regards,
Octavian
The json-to-xml() function parameter must be the JSON file content. When you load a JSON file content you need to use the unparsed-text() function. Something like this
Code: Select all
<xsl:variable name="json-xml" select="json-to-xml(unparsed-text($input))"/>
There is also a webinar and a vide demo that shows how to convert JSON to XML using XSLT:
https://www.oxygenxml.com/demo/json_query.html
https://youtu.be/wRgvWEKo6_w?t=2374
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service