CDATA and XSL
-
I have been trying to transform XML with the .net xml transforms control. One of the elements has CDATA sections, how do I isolate the first CDATA section and read the text from it and not the other? Also when I try to include the image in the xml transform control all I get is the image string and not the image itself. Can I include images when i'm transforming data with xsl and the xml transform control. ]]> Sorry if my question is poorly written, i've never really used xsl. Paul
PJ
-
I have been trying to transform XML with the .net xml transforms control. One of the elements has CDATA sections, how do I isolate the first CDATA section and read the text from it and not the other? Also when I try to include the image in the xml transform control all I get is the image string and not the image itself. Can I include images when i'm transforming data with xsl and the xml transform control. ]]> Sorry if my question is poorly written, i've never really used xsl. Paul
PJ
AFAIK, when you transform an XML document using XSLT, CDATA sections and regular text are parsed together as one text item. However, you can parse CDATA sections and regular text separately using the XmlDocument class. Given the above information, you can use the Add Extension Object feature of the XsltArgumentList to achieve your purpose. IMHO, the below code is a bit overkill but it does the job. By the way, your second CDATA section will be transformed as text as and not an HTML element. To create a HTML element, you have to create it dynamically or statically in the XSLT code.
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Xml::XPath;
using namespace System::Xml::Xsl;
public ref class ParseCdata
{
public: