Reputation: 119
I want to remove the duplicate <br />
tag in a CDATA section using XSLT.
<data>
<![CDATA[ Hello <br /> <br /> <br /> how are you? ]]>
</data>
The output I'm expecting is
<data>
Hello <br /> How are you?
</data>
How can this be done?
Upvotes: 0
Views: 791
Reputation: 163625
There are no tags inside a CDATA section. CDATA means "character data"; putting a string inside CDATA has one purpose only, which is to say "Anything in here that looks like a tag is not actually a tag, it is ordinary characters".
If the person who created the XML didn't realize this and foolishly put CDATA around markup that they wanted to be treated as markup, then your recovery action is to extract the content of the CDATA section, wrap an element around it, and then submit it to an XML parser for parsing. Some XSLT processors have built-in extensions (e.g. saxon:parse()) to do this, in others you may be able to call out to Java or Javascript.
Upvotes: 2