javascript – Is there a way to do variable substitution for xml that is inside of a json object?

The JSON you’ve shown us isn’t well formed: the quotes around “ABC” and “123 abc” need to be either omitted, or escaped as \".

If we ignore that problem, the following XSLT 3.0 transformation should do the job:

<xsl:transform version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="input-uri"/>
<xsl:variable name="json" select="json-doc($input-uri)"/>
<xsl:output method="json" indent="yes"/>

<xsl:template name="xsl:initial-template">
  <xsl:map>
     <xsl:map-entry key="'language'" select="$json?language"/>
     <xsl:map-entry key="'demoXml'">
       <xsl:variable name="final-xml">
         <xsl:apply-templates select="parse-xml($json?demoXml)"/>
       </xsl:variable>
       <xsl:sequence select="serialize($final-xml)"/>
     </xsl:map-entry>
  </xsl:map>
</xsl:template>

<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="Language">
  <Language><xsl:value-of select="$json?language"/></Language>
</xsl:template>

</xsl:transform>

(Not tested).

Read more here: Source link