|
|
Hi all,
I'm trying to convert a .NET DataSet into something viewable by a webbrowser. Its trivial to get the dataSet into XML format (.WriteXML), and then I need to transform that with an XSLT transformation. The problem is, the dataset comes back as xml like this:
<br />
...<br />
<Table><br />
<OBJECT_NAME>ADD_ADZIP</OBJECT_NAME><br />
<OBJECT_ID>164116</OBJECT_ID><br />
<OBJECT_TYPE>PROCEDURE</OBJECT_TYPE><br />
<CREATED>2003-06-19T14:08:03.0000000-04:00</CREATED><br />
<LAST_DDL_TIME>2003-06-19T14:10:19.0000000-04:00</LAST_DDL_TIME><br />
<TIMESTAMP>1998-12-22:11:10:19</TIMESTAMP><br />
<STATUS>VALID</STATUS><br />
</Table><br />
<Table><br />
<OBJECT_NAME>ADD_LABEL</OBJECT_NAME><br />
<OBJECT_ID>164202</OBJECT_ID><br />
<OBJECT_TYPE>FUNCTION</OBJECT_TYPE><br />
<CREATED>2003-06-19T14:08:11.0000000-04:00</CREATED><br />
<LAST_DDL_TIME>2003-06-19T14:10:20.0000000-04:00</LAST_DDL_TIME><br />
<TIMESTAMP>1998-12-22:11:10:20</TIMESTAMP><br />
<STATUS>INVALID</STATUS><br />
</Table><br />
...<br />
Which is fine but I get lost when it comes to transforming this data with an XSLT file. The problem is I need to know the element names (OBJECT_NAME, OBJECT_ID, etc) for the html file, but I do not want to hard-code these names into my .xslt file, nor do I wish to generate one on the fly.
To give you some more background: All this app does is select some rows from a user defined table and outputs them to some files (CVS, tab delimited, and xml/html). The html is nothing fancy, I just want to dump them into a standard html table that is viewable in a browser, with field names at the top and data beneath it.
This doesnt seem like it should be too hard to do. Every example of XSLT Ive seen is very clear and straightforward, I just havent been able to find anything about grabbing an elements name, and Im not sure how to change the format of the XML given by the dataset (which would be another solution - if I just formatted the xml differently).
Any suggestions? Thanks
Dave Ratti
|
|
|
|
|
use need to use the name() function in xslt.
In order to not hard code element names you should pass them as parameters to your xslt.
so something like:
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet <br />
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
version="1.0" ><br />
<br />
<xsl:param name="column_name">object_NAME</xsl:param><br />
<br />
<xsl:template match="/"><br />
<xsl:value-of select="//table/*[name() = $column_name]/text()"&/><br />
</xsl:template><br />
<br />
</xsl:stylesheet>
if you don't pass a parameter to your xslt, then it will default to 'object_NAME'.
c# calling code:
XslTransform xslt = new XslTransform();<br />
XmlDocument document = new XmlDocument();<br />
document.LoadXml(xmlFileName);<br />
xslt.Load(stylesheetFileName);<br />
<br />
MemoryStream ms = new MemoryStream();<br />
XPathNavigator nav = document.CreateNavigator();<br />
<br />
XsltArgumentList xslArg = new XsltArgumentList();<br />
<br />
xslArg.AddParam("column_name", "", "name of column you want");<br />
<br />
xslt.Transform(nav, xslArg, ms, null);<br />
<br />
StreamReader sr = new StreamReader(ms);<br />
ms.Position = 0;<br />
string result = sr.ReadToEnd();<br />
sr.Close();
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Great, thanks.
One more question - what if I dont know how many columns the table is going to have? I think I might be able to hack something together with mxlns:script, unless anyone has a better idea?
Thanks
Dave Ratti
|
|
|
|
|
as you guessed you will have to scripting to do this - version 1 of xsl is pretty bare bones...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Ok, thanks for your time; you were very helpful
Dave ratti
|
|
|
|
|
When i search a certain xml-file using "selectNodes("//ROOT/BLA")" and i receive the found nodes. Is it possible to get iterate through those found nodes and retrieve their current position in the xml-tree? (remember that this is DOM and not XSLT, so "position()" and all that crap won't work).
Any help is greatly appriciated.
|
|
|
|
|
by position I presume you mean name - you could use:
XmlNodeList results = document.SelectNodes(""
foreach (XmlNode result in rtesults)<br />
{<br />
Console.Write("found {0} value = '{1}'", GetNodeName(result), result.value);<br />
}<br />
<br />
string GetNodeName(XmlNode node)<br />
{<br />
string result = node.LocalName;<br />
<br />
if (node.Parent != null)<br />
result = GetNodeName(node.Parent) + "/" + result;<br />
<br />
return result;<br />
}
if you want the position then just change the above function to count previousSiblings:
<br />
string GetNodePosition(XmlNode node)<br />
{<br />
int previousSiblings = 0; <br />
for (XmlNode previous_node = node.PreviousSibling; previous_node != null; previous_node = previous_node.PreviousSibling)<br />
previousSiblings++;<br />
string result = previousSiblings.ToString();<br />
<br />
if (node.Parent != null)<br />
result = GetNodeName(node.Parent) + "/" + result;<br />
<br />
return result;<br />
}
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
yeah...i thought i would have to write my own function to calculate the current position. I was hoping i overlooked something and that it was possible to retrieve the index/position directly from a found node. Thanks though, for your reply.
|
|
|
|
|
I am attempting to create a generic xml schema file that defines element type restrictions. That file is then imported into my additional xml schemas, which make use of the defined types. Here is what I have.
General Formatting File
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<xs:schema id="GeneralFormatting" <br />
targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd"<br />
elementFormDefault="qualified"<br />
xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd"<br />
xmlns:xs="http://www.w3.org/2001/XMLSchema"><br />
<br />
<!-- Define format restriction --> <br />
<xs:simpleType name="UserName"><br />
<xs:restriction base="xs:string"><br />
<xs:pattern value="([a-zA-Z0-9])*"></xs:pattern><br />
<xs:whiteSpace value="preserve" /><br />
</xs:restriction><br />
</xs:simpleType><br />
</xs:schema><br />
XML Schema
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<xs:schema id="WTNManagement_XSD" <br />
targetNamespace="http://localhost/XMLWebServices/Management.xsd" <br />
elementFormDefault="qualified" <br />
xmlns:tns="http://localhost/XMLWebServices/Management.xsd"<br />
xmlns:xs="http://www.w3.org/2001/XMLSchema"><br />
<br />
<xs:import <br />
namespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" <br />
schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /><br />
<br />
<!-- definition of elements --><br />
<xs:element name="Management" id="Management"><br />
<xs:complexType><br />
<xs:sequence><br />
<!-- File Sequence number, must be unique --><br />
<xs:element name="SeqNum" type="xs:integer" /><br />
<!-- User making request --><br />
<xs:element name="UserName" type="xs:UserName" /><br />
</xs:sequence><br />
</xs:complexType><br />
</xs:element><br />
</xs:schema><br />
This code isn't working could someone point me in the right direction.
Thanks
Jason W.
|
|
|
|
|
You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd"
and then have <xs:element name="UserName" type="gf:UserName">
|
|
|
|
|
Something like this?
Generic Formatting XML Schema
<?xml version="1.0" encoding="utf-8" ?><br />
<xs:schema id="GeneralFormatting" <br />
targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd"<br />
elementFormDefault="qualified"<br />
xmlns:ns="http://localhost/XMLWebServices/GeneralFormatting.xsd"<br />
xmlns:xs="http://www.w3.org/2001/XMLSchema"><br />
<br />
<!-- Define format restriction --> <br />
<xs:simpleType name="UserName"><br />
<xs:restriction base="xs:string"><br />
<xs:pattern value="([a-zA-Z0-9])*"></xs:pattern><br />
<xs:whiteSpace value="preserve" /><br />
</xs:restriction><br />
</xs:simpleType><br />
</xs:schema><br />
Additional XML Schema
<?xml version="1.0" encoding="utf-8" ?><br />
<xs:schema id="WTNManagement_XSD" <br />
targetNamespace="http://localhost/XMLWebServices/Management.xsd" <br />
elementFormDefault="qualified" <br />
xmlns:tns="http://localhost/XMLWebServices/Management.xsd"<br />
xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" <br />
xmlns:xs="http://www.w3.org/2001/XMLSchema"><br />
<br />
<xs:import <br />
schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /><br />
<br />
<!-- definition of elements --><br />
<xs:element name="Management" id="Management"><br />
<xs:complexType><br />
<xs:sequence><br />
<!-- File Sequence number, must be unique --><br />
<xs:element name="SeqNum" type="xs:integer" /><br />
<!-- User making request --><br />
<xs:element name="UserName" type="gns:UserName" /><br />
</xs:sequence><br />
</xs:complexType><br />
</xs:element><br />
</xs:schema>
Thanks
Jason W.
|
|
|
|
|
Here are the details of the error message I’m getting.
<br />
Type ‘http:
Hope that helps.
Jason W.
|
|
|
|
|
In your first schema you should change the xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" to xmlns="http://localhost/XMLWebServices/GeneralFormatting.xsd" so that all types declared are in that namespace, otherwise you would have to put the gns prefix on all type names...
|
|
|
|
|
Does anybody know where i could find an amazon.com rss file or any other book store rss files.................thanks
Da Intern
|
|
|
|
|
Hi
I'm trying to generate an xml browseroutput using classic ASP, VBScript and Set objXML=server.CreateObject("MSXML.DOMDocument")
I've addes some elements. But In an allready created element, how do I get the childnodes.length? It should be something like num=objXML.firstChild.childnodes.length??? but I don't know the correct syntax.
Can somebody please help? /xaphod
|
|
|
|
|
All efforts at generating a £ sign in the output HTML have failed. Any suggestions?
|
|
|
|
|
I am not sure about this but have you tried &<m>pound; ?
Paul Watson Bluegrass Cape Town, South Africa
Roger Wright wrote:
Personally, I'm seeking a red-headed, double-breasted mattress thrasher
|
|
|
|
|
£ -> £
£ -> £
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I would hope anyone can help me understand a certain problem I am currently having with a small piece of code. I would be very grateful if anyone could give me some ideas on how I could structure my XSL template to produce an output similar to the following table given the attached Test.xml source. I seem to be using for-each and the priority attribute but cant pinpoint where to place it correctly.
View the Test.xml source at :
http://www.angelfire.com/pro/atbgmxsl/Test.xml
Required result in table format is :
ASXCode Company Name Company Statistics/Interim Dates Annual Balance Sheet/Cash
RWS Rothbury Wines Limited -- 99,000
OCO Oriel Communications Limited 12/2002 97,065
NRL Newland Resources Limited 12/2002 95,143
MCL M2M Corporation Limited 12/2002 95,033
SUP Supersorb Environment NL 12/2002 94,328
|
|
|
|
|
Just a quick shot at it
<table>
<xsl:for-each select="root/ResultSet/Record">
<tr>
<xsl:for-each select="Column">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
|
|
|
|
|
I’m creating my first web service and running into the following error.
A first chance exception of type 'System.Net.WebException' occurred in system.dll
Additional information: The remote server returned an error: (401) Unauthorized.
The error occurs in the Reference.vb file when I try to retrieve a string value from a function in the asmx file. Here is some of the code from the Reference.vb file.
<br />
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/XMLWebServices/ReturnValue", RequestNamespace:="http://localhost/XMLWebServices ", ResponseNamespace:="http://localhost/ XMLWebServices ", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _<br />
Public Function ReturnValue() As String<br />
Dim results() As Object = Me.Invoke("ReturnValue", New Object(-1) {})<br />
Return CType(results(0), String)<br />
End Function<br />
The web method in the asmx file looks like the following.
<WebMethod()> Public Function ReturnValue() As String<br />
ReturnValue = "Value"<br />
End Function<br />
All suggestions are greatly appreciated.
Jason W.
|
|
|
|
|
Must define Credentials
<br />
Dim ws As New localhost.WebS()<br />
ws.Credentials = System.Net.CredentialCache.DefaultCredentials<br />
Jason W.
|
|
|
|
|
im building a web page and i want to be able to search an xml file
please help
thanks
Da Intern
|
|
|
|
|
You'll need to ask a more detailed question if you want help.
What do you need help with?
|
|
|
|