[xsl] Json to xml

Subject: [xsl] Json to xml
From: "dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Mar 2025 18:24:42 -0000
I'm trying this for the forst time and it is generally working well, but I've come up with an odd result. My main stylesheet looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:xs="http://www.w3.org/2001/XMLSchema";
	xmlns:j="http://www.w3.org/2005/xpath-functions";
	exclude-result-prefixes="xs j"
	version="3.0">

<xsl:output indent="yes" method="text"/>

<xsl:include href="jsonxml.xsl"/>


<!-- WARNING: CONVERTED JSON is in a default namespace "http://www.w3.org/2005/xpath-functions"; -->
<xsl:template match="data">
<xsl:variable name="MAPFILE" select="json-to-xml(.)"/>
<xsl:variable name="connectorID" select="$MAPFILE/j:map/j:string[@key='serviceName']"/>


<xsl:result-document method="xml" indent="yes" href="{concat($connectorID, '.xml')}" >
<xsl:copy-of select="$MAPFILE"/>
</xsl:result-document>


<xsl:result-document method="text" href="{concat($connectorID, '.adoc')}">
<xsl:apply-templates select="$MAPFILE"/>
</xsl:result-document>
</xsl:template>




</xsl:stylesheet>

I do the conversion here and save a file with the XML and then process the content to produce an asciidoc (adoc) file. The real work is done in the included xsl file.

I've done it this way because I find it easer to develop and test the second XSLT in oXygen and use the generated XML file for the input to it. I expected to get the same results of using this stylesheet with the JSON file, or using the XML file with the included stylesheet. For some reason I get completely different results. I end up missing content when I run the process from this stylesheet. This content is in a namespace but so is the XML file, so my stylesheet shouldn't be dropping out content because of this, but it seems like what is going on that a namespace is not correct.

Any thoughts on why this might be happeniing? I used this approach with an XML starting point and it worked great to be able to switch from processing all the content vs individual files.

I'll try and see if I can make a small sample JSON and associated included XSLT.

..dan

Current Thread