Search code examples
xmlxsltcdata

How to parse CDATA or replace CDATA new line with <BR> in XSL?


I have an external xml feed with a CDATA content (in plain text format)

<RSS_Description><![CDATA[
This is the documentation for Book 1

This is published by Mr Smith

This is 3rd edition of publishing
]]></RSS_Description>

Now I have my xsl to retrieve this with the "disable-output-escaping" attribute.

RSS Description :<br><xsl:value-of select="RSS_Description" disable-output-escaping="yes"/>

And it shows 1 line of content in the browser view.

It looks something like this.

RSS Description : This is the documentation for Book 1This is published by Mr SmithThis is 3rd edition of publishing

My question: Is there a way to make the display the same as the retrieved XML node? With the line break.

RSS Description : 
This is the documentation for Book 1

This is published by Mr Smith

This is 3rd edition of publishing

Solution

  • If you transform to HTML then use the pre element e.g.

    <pre style="white-space: pre;">
      <xsl:value-of select="RSS_Description"/>
    </pre>