Question

I need to transform the XML inside the CDATA of the XML using the XSLT.

Input:

<pre>
  <![CDATA[<p><strong>Guidance</strong> about simplifying medication in <em>patients<em> with <a href="/formulary/en/drug-treatment-in-the-imminently-dying.html#heart-failure">end-stage CHF who appear to be imminently dying</a>.</p>]]>
</pre>

Output:

<ce:section-title>Pre</ce:section-title>
<ce:para><ce:bold>Guidance</ce:bold> about simplifying medication in <ce:italic>patients</ce:italic> with <ce:inter-ref xlink:type="simple" xlink:href="/formulary/en/drug-treatment-in-the-imminently-dying.html#heart-failure">end-stage CHF who appear to be imminently dying</ce:inter-ref>.</ce:para>

Could you please suggest me on this. Thanks in advance.

Was it helpful?

Solution

Which XSLT processor and which version of XSLT can you use? With the commercial versions of Saxon 9 you can use XSLT 3.0 and

<xsl:template match="pre">
  <ce:section-title>Pre</ce:section-title>
  <xsl:apply-templates select="parse-xml(.)"/>
</xsl:template>

<xsl:template match="p">
  <ce:para>
    <xsl:apply-templates/>
  </ce:para>
</xsl:template>

<!-- now add similar templates here for transformation of strong, em etc -->
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top