473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml transform using xslt

I have an xml file:

<?xml version="1.0" encoding="utf-8" ?>
<G2Registers
xmlns="http://tempuri.org/registers.xsd">
<register>
<name>Version Register</name>
<address>"00000 000"</address>
<verilogname>"P PC_Version"</verilogname>
<bitfield>
<name>"Xilinx Part"</name>
<startbit>19</startbit>
<endbit>16</endbit>
</bitfield>
<bitfield>
<name>"Revisi on Number"</name>
<startbit>15</startbit>
<endbit>0</endbit>
</bitfield>
<type>"Status "</type>
</register>
</G2Registers>

The real file has lots of <register> elements, not just one.

The schema file "registers. xsd" was created by visual studio .net from the
xml file.

I read in an xml file and schema like so:

regDoc = New XmlDataDocument
Try
regDoc.DataSet. ReadXmlSchema(x sdFileName)
Catch e As Exception
Console.WriteLi ne("Exception: " & e.ToString())
End Try
regDoc.Load(xml FileName)

At this point, everything is fine and my data lives in regDoc.DataSet.

Now I want to use an xsl Transform to create an html file with some of the
data. I use the following xslt file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="G2Regist ers">
<html>
<body>
<table border="1">
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="register ">
<tr>
<td><xsl:valu e-of select="name"/></td>
<td><xsl:valu e-of select="address "/></td>
</tr>
</xsl:template>
</xsl:stylesheet>

using the following code:

Private Sub write_html(ByVa l xml_doc As XmlDocument, ByVal xls_doc As String, ByVal html_doc As String)
Dim tfm As New Xsl.XslTransfor m
Dim newDoc As New IO.StringWriter
Dim xpn As System.Xml.XPat h.XPathNavigato r
Dim root As XmlElement = xml_doc.Documen tElement

xpn = root.CreateNavi gator()

tfm.Load("..\re g_to_html.xslt" , Nothing)
Dim writer As XmlTextWriter = New XmlTextWriter(" ..\registers.ht m", Nothing)
tfm.Transform(x pn, Nothing, writer, Nothing)
End Sub

However, the resulting file just contains a single line which is a
concatenation of all the elements and attributes from the xml file.

I have discovered that if I remove the namespace line:

xmlns="http://tempuri.org/registers.xsd"

from the source xml file, that the transform works properly and creates
the html file with tables and so on. But if I do this, then the DataSet
(regDoc.DataSet ) contains no data. It does have the schema read in and the
tables defined in the schema exist, but they are empty.

Surely there is a way around this problem??

Thanks for taking the time to read a long post.

Terry Brown
Stickman Software
http://www.stickmansoftware.com

Nov 21 '05 #1
0 1268

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3610
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
8
2176
by: Luther Miller | last post by:
I am using the XML tranform functionality in .NET to transform data in a DataSet into XMLSS using an XSLT file I have created. There are about 100 columns and only about 120 rows in the data table being transformed - modest amount of data to say the least. The transform takes at least 10 seconds on a fast machine, which seems absolutely ridiculous. The DataSet contains many other tables in addition to the one I am
3
2478
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator) and saw that it works just fine. Now what I mean by not working is that it just silently fails to produce the expected output... no exceptions are being thrown. Xselerator uses msxml 3 so it's not really helping me see the problem in .net 1.1. ...
4
4823
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt transform via code? Any examples would be great.
3
2134
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty string. I expected the xml to be transformed into a plain text document. Everything works fine when i transform using XmlPad. Here's the code (which does generate the Xml properly): Sample XML:
1
2687
by: Danny Lesnik | last post by:
Hi i have my XML file c:\prd.xm <?xml-stylesheet type="text/xsl" href="prd.xsl"?><products><product><a>2</a><b>3</b></product><product><a>4</a><b>2</b></product></products This is my XSL file <?xml version="1.0" encoding="windows-1255" ?><xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:utils="urn:galileo-com:msxsl-jscript-utilities" version="1.0"><xsl:template...
3
302
by: Peter Row | last post by:
Hi, I have 2 XML files and 1 XSLT file. The second XML file has the following declarative 1st line: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> ....the 1st one (the one to be transformed) doesn't. In the transform file I load the 2nd XML file which contains
4
2097
by: WStoreyII | last post by:
I wish to know how to set it up so that when an xml webservice is called that instead of displaying the xml in the browser it will render it with a xslt file the problem is i dont know how to do this? Thanks again WStoreyII
1
2620
by: Steve | last post by:
Using VB.NET 2.0 I have a simple routine that attempts transforms an XmlDocument with an XSLT stylesheet into HTML. Under the old 1.1 framework with XslTransform, everything worked fine. Now using XslCompiledTransform, the Transform method hangs. My code: Function TransformXML(ByRef FacXML As Xml.XmlDocument, ByVal XslFile As String) As String Dim xslt As New System.Xml.Xsl.XslCompiledTransform Dim xmlFile As String = <code to name...
12
2920
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform the file. Here is the code snippet: XPathDocument xdoc = new XPathDocument(fs); XPathNavigator nav = xdoc.CreateNavigator(); xslt.Transform(nav, null, strWriter, null);
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.