How can i put all tag contents into CDATA?

D

DZ

How can i put all tag contents into <![CDATA[...]]> (i mean using XSL)

For example. I have

....
<name>
<firstname>John</firstname>
<lastname>Malkovich</lastname>
<name>
.....

And i want to get:
<name><![CDATA[
<firstname>Alexey</firstname>
<lastname>Alexeev</lastname>
]]></name>
 
P

Patrick TJ McPhee

% How can i put all tag contents into <![CDATA[...]]> (i mean using XSL)
%
% For example. I have
%
% ...
% <name>
% <firstname>John</firstname>
% <lastname>Malkovich</lastname>
% <name>
% ....
%
% And i want to get:
% <name><![CDATA[
% <firstname>Alexey</firstname>
% <lastname>Alexeev</lastname>
% ]]></name>

You can't do this with XSL. What you've written is exactly the same as

<name>
&lt;firstname>Alexey&lt;/firstname>
&lt;lastname>Alexeev&lt;/lastname>
</name>

and the XSLT processor is free to pick its quoting method, which will
always be to use &lt; because apart from me nobody seems to like CDATA
sections much.

Actually, I suppose you could do it by building it (including the <!CDATA[[
and ]]>) in an xsl:text element and disabling output escaping, then
serialising the result tree. I'll leave that as an exercise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top