My xml element content is having special characters like <,>,[,]. I want to find element macthing the content <![CDATA[someText]]>
and replace it with some new value like <![CDATA[newValue]]>
.
<property name="sourcePath">
<string><![CDATA[someText]]></string>
</property>`
I am trying to do this using below xsl template. But it is not working.
<xsl:template match="property[string='<![CDATA[someText]]>']">
<xsl:element name="string">
<xsl:text disable-output-escaping="yes"><![CDATA[newValue]]></xsl:text>
</xsl:element>
Please help.
A CDATA section is not presereved in the XML INFOSET, so its contents is just regular text -- a complete text node or a part of a text node.
In your case the CDATA section is the complete text node, so you can have:
You don't need to use DOE or CDATA -- just escape the characters in NewValue and use the
cdata-section-elements="string"
attribute of the<xsl:output>
declaration.And here is the complete solution:
when this transformation is applied on the following XML document:
the wanted, correct result is produced: