|
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<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;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
any one please tell me how to read http xml attribute values and CDATA part using javascript...
it's urgent please... help me...
Pradeep Reddy
|
|
|
|
|
Hi everyone,
well I'm building an XSL Style sheet here and i thought it would be a really nice feature if i could show the names of my nodes which are mostly in the form : 'LogConfiguration' to 'Log Cofiguration'
For now my problem is just to know how to convert such a string into this form.
Thanks in advance
Rocky
You can't climb up a steep ladder with your hands in your pockets.
|
|
|
|
|
Hi
I am getting following error on connection string in xmlbulkload:
"QueryInterface for interface SQLXMLBULKLOADLib.ISQLXMLBulkLoad failed."
Thanks
Hardik Panchal
|
|
|
|
|
i got the solution
tx
Hardik Panchal
|
|
|
|
|
Would you please suggest me taht how to process large .csv files(more than 1000 lines) FASTER, so that it can be processed faster by XML Processor to convert into xml files.
But it works with small file(less than 1000 lines). But incase of large .csv files it gives following Memory Managament Error.
"Your system is low on virtual memory.Windows is increasing the size of the virtual memory paginf file...."
Please solve my problem with the code in C#.NET
With Regards
Tapan
|
|
|
|
|
hi every buddy!
well I'm trying to display the XML data (sample given below ) in a table using XSL and as i've highlighted in the XML the results node is the one giving me trouble. I'm trying to do this in XSL as:
<tr class="nonSelectedRow">
<pre><xsl:for-each select="*[node() and node()!='Results']"></pre>
<th><xsl:value-of select="name()"/></th>
</xsl:for-each>
</tr>
-------------------------------------------
The problem is that I wanna display the data in two seperate tables such as
<pre>----------------------------------------
inputs |
----------------------------------------
property | phase | basis | calc | Value |
----------------------------------------</pre>
and...........
<pre>
----------------------------------------------------
inputs | Outputs |
----------------------------------------------------
property | phase | basis | calc | Compound |Value |
----------------------------------------------------</pre>
The XML part is given here:
--------------------------------
<code>
<CallSequence>
<Call>
<ObjectType>Material Object</ObjectType>
<ObjectName>Mix out</ObjectName>
<Interface>ICapeThermoMaterialObject</Interface>
<Method>SetProp</Method>
<Arguments>
<Property>Volume</Property>
<Phase>Overall</Phase>
<Basis>Mole</Basis>
<Calc>Mixture</Calc>
<pre> <Results>
<Value>0.000018075</Value>
</Results></pre>
</Arguments>
<ReturnCode>No Error</ReturnCode>
</Call>
<Call>
<ObjectType>Material Object</ObjectType>
<ObjectName>Mix out</ObjectName>
<Interface>ICapeThermoMaterialObject</Interface>
<Method>GetProp</Method>
<Arguments>
<Property>Fraction</Property>
<Phase>Overall</Phase>
<Basis>mole</Basis>
<Calc>null</Calc>
<pre> <Results>
<Compound>
<Name>Hydrogen</Name>
<Value>0.355979900</Value>
</Compound>
<Compound>
<Name>Methane</Name>
<Value>0.018735784</Value>
</Compound>
<Compound>
<Name>Benzene</Name>
<Value>0.401813320</Value>
</Compound>
<Compound>
<Name>Toluene</Name>
<Value>0.223470992</Value>
</Compound>
<Compound>
<Name>BiPhenyl</Name>
<Value>0.000000005</Value>
</Compound>
</Results></pre>
</Arguments>
<ReturnCode>No Error</ReturnCode>
</Call>
</CallSequence>
</code>
Can anyone tell me how to display the data in this format using the way I'm trying to do in XSL. Coz I wanna make it as general as possible. I dont wanna be specific so that it can cater the changes in the future.
Thanks in advance!!!
Rocky
You can't climb up a <i>steep</i> ladder with your hands in your pockets.
|
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Call Sequence</title>
</head>
<body>
<xsl:apply-templates select="CallSequence/Call/Arguments"/>
</body>
</html>
</xsl:template>
<xsl:template match="Arguments">
<table>
<tr>
<xsl:apply-templates select="*[name() != 'Results'] | Results/child::node()[1] | Results/child::node()[1] / child::node()[2]"/>
</tr>
</table>
</xsl:template>
<xsl:template match="*">
<th><xsl:value-of select="name()"/></th>
</xsl:template>
</xsl:stylesheet>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks u so much George, that worked for me, actually I modified it and used only this part
*[name() != 'Results'] | Results/child::node()[1] | Results/child::node()[1] / child::node()[2]
just for the confirmation i wanna ask you that '[2]' selects two child nodes right??
and by the way can u tell me the name of some really good book on XML/XSL?
Thanks again... you Rock
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
The XPath 'Results/child::node()[1]/child::node()[2]' selects the second child 'child::node()[2]' of the first child 'child::node()[1]' of the element 'Results'. The '[2]' actually means 'position() = 2'. You can kind of think of '[2]' as an array index, where the base is 1.
I have learned XSLT from the first edition of this book:
XSLT Programmer's Reference, Second Edition
by Michael Kay
Wrox Press © 2001 (938 pages)
ISBN:0764543814
There is also a third edition the covers XSLT 2.0:
XSLT 2.0 Programmer's Reference, Third Edition
by Michael Kay
Wrox Press © 2004 (955 pages)
They have a tutorial/reference type structure which makes them useful for some time.
I also found the following useful also:
XSLT Cookbook, Second Edition
by Sal Mangamo
O'Reilly Media,Inc. © 2006 (751 pages)
ISBN: 0-596-00974-7
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks very much u know I really appreciate this. I'll try and get hold of these books!
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
Alternative:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Call Sequence</title>
</head>
<body>
<xsl:apply-templates select="CallSequence/Call/Arguments"/>
</body>
</html>
</xsl:template>
<xsl:template match="Arguments">
<table>
<tr>
<xsl:apply-templates select="*"/>
</tr>
</table>
</xsl:template>
<xsl:template match="*">
<th><xsl:value-of select="name()"/></th>
</xsl:template>
<xsl:template match="Results">
<xsl:apply-templates select="*[1] | *[1]/Value"/>
</xsl:template>
</xsl:stylesheet>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
i'd would like to add that line <?xml-stylesheet type=\"text/xsl\" href=\"{0}\"?>
to my xml file using the xmlDocument-Class but i don't know how? Atm i use the following code
using (XmlWriter writer = XmlWriter.Create(FullFilePath, settings))
{
writer.WriteRaw(string.Format("<?xml-stylesheet type=\"text/xsl\" href=\"{0}\"?>", Globals.StylesheetXSL));
writer.WriteStartElement("root");
writer.WriteEndElement();
writer.Flush();
writer.Close();
}
-- modified at 10:49 Thursday 30th August, 2007
|
|
|
|
|
error1408 wrote: using the xmlDocument-Class
error1408 wrote: using (XmlWriter writer = XmlWriter.Create(FullFilePath, settings))
XmlWriter is NOT XmlDocument. I strongly recommend you use the documentation[^] to find information.
|
|
|
|
|
I KNOW, that is the code I use at the moment...
I do not know how to do exactly the same with the xmlDocument-Class. Thats why i'm asking.
|
|
|
|
|
error1408 wrote: I do not know how to do exactly the same with the xmlDocument-Class.
I fail to see how that negates my original reply... I strongly recommend you use the documentation to find information.
|
|
|
|
|
I searched the documentation for my problem. And i found nothing. I checked every method.
And because i found nothing, i asked you.
|
|
|
|
|
error1408 wrote: I searched the documentation for my problem. And i found nothing.
You should probably provide that information in your initial post.
error1408 wrote: I checked every method.
I guess you missed this one[^]
|
|
|
|
|
THANK YOU. You're the man! Why didn't i see it before? At last the ugly code can be banished! Hurray
led mike wrote: You should probably provide that information in your initial post.
Yes perhaps
|
|
|
|
|
I wonder why Microsoft keeps hiding this information in the documentation?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Yeah and Google is culpable as well since they provide a perfectly usable Search Engine.
|
|
|
|
|
I'm trying to create ASPX page with DataGrid, that includes template column, which looks like TextBox. I order to enable data binding to textbox I'm using the following syntax:
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>' ID="txtID" /> using XSL.
I supposed, the XSL code should be the same, while escaping '<','>' etc.:
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>' ID="txtID" />.
In this case I'm getting the following error:
Parser Error Message: Code blocks are not supported in this page, because it is not compiled.
Please, assist.
Alex
-- modified at 10:06 Wednesday 29th August, 2007
|
|
|
|
|
It is objecting to the "<%# ... %>" code which gets placed in the .aspx page before it gets compiled. By the time you place your code in the page, the page has already been compiled. Also, why place a textbox in this way when you can do it statically in design mode?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Is there any workaround? Is it possible to implement this in code-behind file?
|
|
|
|
|
There are a some ways but you have to stay away from the code blocks. You may need to as your question in the ASP.NET Forum to get a better answer, but you can use XSL in the creation of a custom control or during the binding processs you can add content to a cell or even modify the whole row. However, you have to stay away from coding blocks.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|