This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Generating CDATA through XSLT       Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Generating CDATA through XSLT       " Watch "Generating CDATA through XSLT       " New topic
Author

Generating CDATA through XSLT

Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
Hi All,

How can I write XSLT that outputs CDATA nodes?

For example, how would I modify XSLT code that looks like this:

<xsl:element name="root">
<xsl:element name="node">
<xsl:value-of select="value"/>
</xsl:element>
</xsl:element>

to produce an output like this:

<root>
<node><![CDATA[ This is my value ]]></node>
</root>


Tushar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42041
    
  64
You need an "<xslutput cdata-section-elements="node"/>" element. Here's some more information on xslutput.


Ping & DNS - my free Android networking tools app
Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
Hi

I tried given code but its not working

I am generating XML through XML using XSLT and I want the following output



This is what i have written. Please help how to add <![CDATA[]]>



Please let me know if any explaination is required
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42041
    
  64
So what does your xslutput element look like?
Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
It is giving an error

Element must only be used at top level of stylesheet and Element must be empty

This is how i used it, and code is under template tag

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Generating CDATA through XSLT