Click here to Skip to main content
16,005,491 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
Stefan Troschuetz6-Aug-07 23:15
Stefan Troschuetz6-Aug-07 23:15 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
zxc896-Aug-07 23:23
zxc896-Aug-07 23:23 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
Stefan Troschuetz6-Aug-07 23:40
Stefan Troschuetz6-Aug-07 23:40 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
zxc896-Aug-07 23:51
zxc896-Aug-07 23:51 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
zxc896-Aug-07 23:52
zxc896-Aug-07 23:52 
GeneralRe: How to allow boolean 'TRUE' or 'True' in xml Pin
Stefan Troschuetz7-Aug-07 0:29
Stefan Troschuetz7-Aug-07 0:29 
QuestionCDATA and XSL Pin
pjackson186-Aug-07 20:20
pjackson186-Aug-07 20:20 
AnswerRe: CDATA and XSL [modified] Pin
George L. Jackson7-Aug-07 14:42
George L. Jackson7-Aug-07 14:42 
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:


    ParseCdata(String^ xmlText) : doc(gcnew XmlDocument)


    {


        doc->LoadXml(xmlText);


    }


 


    String^ GetCData(XPathNodeIterator^ nodes)


    {


        StringBuilder^ result = gcnew StringBuilder;


 


        while (nodes->MoveNext())


        {


            XPathNavigator^ nodesNav = nodes->Current;


 


            String^ xpath = String::Format("/test/data[@id='{0}']",


                nodes->Current->GetAttribute("id", String::Empty));


 


            XmlNodeList^ dataNodes = doc->SelectNodes(xpath);


 


            for each (XmlNode^ node in dataNodes)


            {


 


                for each (XmlNode^ child in node->ChildNodes)


                {


                    if (child->NodeType == XmlNodeType::CDATA)


                    {


                        result->AppendFormat("-!!!{0}!!!-", child->Value);


                    }               


                }   


            }


        }


 


        return result->ToString();


    }


 


private:


    XmlDocument^ doc;


};


 


 


int main(array<System::String ^> ^args)


{


    String^ xmlText =


        "<?xml version='1.0'?>"


        "<test>"


        "    <data id='1'><![CDATA[CDATA1]]><![CDATA[CDATA2]]></data>"


        "</test>";


 


    String^ xsltText =


        "<?xml version='1.0'?>"


        "<xsl:stylesheet version='1.0' "


        "    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"


        "    xmlns:extObj='urn:cdata-conv'>"


        "<xsl:template match='/'>"


        "<result>\n"


        "\t<xsl:apply-templates select='test/data'/>\n"


        "</result>\n"


        "</xsl:template>"


        "<xsl:template match='data'>"


        "<xsl:value-of select='extObj:GetCData(.)'/>"


        "</xsl:template>"


        "</xsl:stylesheet>";


 


    StringReader^ strReader1;


    XmlReader^ xmlReader1;


    StringReader^ strReader2;


    XmlReader^ xmlReader2;


 


    try


    {


        strReader1 = gcnew StringReader(xsltText);


        xmlReader1 = XmlReader::Create(strReader1);


        XslCompiledTransform^ xslt = gcnew XslCompiledTransform;


        xslt->Load(xmlReader1);


 


        strReader2 = gcnew StringReader(xmlText);


        xmlReader2 = XmlReader::Create(strReader2);


        XPathDocument^ xml = gcnew XPathDocument(xmlReader2);


 


        XsltArgumentList^ xsltArgs = gcnew XsltArgumentList;


        ParseCdata^ cdata = gcnew ParseCdata(xmlText);


        xsltArgs->AddExtensionObject("urn:cdata-conv", cdata);


        xslt->Transform(xml, xsltArgs, Console::Out);


    }


 


    catch (Exception^ excp)


    {


        Console::WriteLine(excp->ToString());


    }


 


    finally


    {


        if (xmlReader2 != nullptr)


            xmlReader2->Close();


 


        if (strReader2 != nullptr)


            strReader2->Close();


 


        if (xmlReader1 != nullptr)


            xmlReader1->Close();


 


        if (strReader1 != nullptr)


            strReader1->Close();


    }


 


    return 0;


}



-- modified at 22:30 Wednesday 8th August, 2007
QuestionOfficeOpen XML and Font Substitution Pin
Dominick Marciano6-Aug-07 10:10
professionalDominick Marciano6-Aug-07 10:10 
AnswerRe: OfficeOpen XML and Font Substitution Pin
Dave Kreskowiak6-Aug-07 10:23
mveDave Kreskowiak6-Aug-07 10:23 
GeneralRe: OfficeOpen XML and Font Substitution Pin
Dominick Marciano7-Aug-07 9:10
professionalDominick Marciano7-Aug-07 9:10 
QuestionMerge XML Pin
Prashant C6-Aug-07 4:06
Prashant C6-Aug-07 4:06 
AnswerRe: Merge XML Pin
led mike6-Aug-07 4:50
led mike6-Aug-07 4:50 
AnswerRe: Merge XML Pin
George L. Jackson6-Aug-07 15:30
George L. Jackson6-Aug-07 15:30 
GeneralRe: Merge XML Pin
led mike7-Aug-07 4:27
led mike7-Aug-07 4:27 
GeneralRe: Merge XML [modified] Pin
George L. Jackson7-Aug-07 15:24
George L. Jackson7-Aug-07 15:24 
GeneralRe: Merge XML Pin
led mike8-Aug-07 4:23
led mike8-Aug-07 4:23 
GeneralRe: Merge XML Pin
George L. Jackson7-Aug-07 16:04
George L. Jackson7-Aug-07 16:04 
QuestionDatabase and XSLT Pin
Prashant C6-Aug-07 2:11
Prashant C6-Aug-07 2:11 
AnswerRe: Database and XSLT Pin
led mike6-Aug-07 4:49
led mike6-Aug-07 4:49 
AnswerRe: Database and XSLT Pin
George L. Jackson6-Aug-07 15:37
George L. Jackson6-Aug-07 15:37 
QuestionCSV to Xml conversion Pin
swapnalim5-Aug-07 19:47
swapnalim5-Aug-07 19:47 
AnswerRe: CSV to Xml conversion Pin
led mike6-Aug-07 4:49
led mike6-Aug-07 4:49 
GeneralRe: CSV to Xml conversion Pin
George L. Jackson6-Aug-07 15:21
George L. Jackson6-Aug-07 15:21 
QuestionPHP excel xml report creating using loops Pin
Dominyka5-Aug-07 12:43
Dominyka5-Aug-07 12:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.