How to Check whether we can use XSL 2.0?
-
Hi everyone, well I'm kind of a new bee here and I wanted to ask a bit naive questions so here it goes. How do we know whether we can use XSL 2.0? Actually I was trying to use the new 'replace' function in XSLT. I changed the header to but its giving me error that replace is not a valid XSLT or XPath Function. So what should I do now? Any ideas?? Thanks in advance Rocky You can't climb up a ladder with your hands in your pockets.
-
Hi everyone, well I'm kind of a new bee here and I wanted to ask a bit naive questions so here it goes. How do we know whether we can use XSL 2.0? Actually I was trying to use the new 'replace' function in XSLT. I changed the header to but its giving me error that replace is not a valid XSLT or XPath Function. So what should I do now? Any ideas?? Thanks in advance Rocky You can't climb up a ladder with your hands in your pockets.
XSLT 2.0 and XPath 2.0 is not available in the current version of .NET. However, you can find .NET libraries here: http://saxon.sourceforge.net/[^] and http://www.altova.com/altovaxml.html[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
XSLT 2.0 and XPath 2.0 is not available in the current version of .NET. However, you can find .NET libraries here: http://saxon.sourceforge.net/[^] and http://www.altova.com/altovaxml.html[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
Or you could use a XSLT Extension Object and write your own replace method. These URLs should help you find the correct path. http://msdn2.microsoft.com/en-us/library/wxaw5z5e(VS.80).aspx[^] and http://msdn2.microsoft.com/en-us/library/tf741884(VS.80).aspx[^]
-
Or you could use a XSLT Extension Object and write your own replace method. These URLs should help you find the correct path. http://msdn2.microsoft.com/en-us/library/wxaw5z5e(VS.80).aspx[^] and http://msdn2.microsoft.com/en-us/library/tf741884(VS.80).aspx[^]
Here is some sample code for XSLT Extension Object that I had playing around with recently: 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 ^args) { String^ xmlText = "" "" " " ""; String^ xsltText = "" "" "" "\n" "\t\n" "\n" "" "" "" "" ""; 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 (strReade