By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

xml transform using xslt

P: n/a
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>"00000000"</address>
<verilogname>"PPC_Version"</verilogname>
<bitfield>
<name>"Xilinx Part"</name>
<startbit>19</startbit>
<endbit>16</endbit>
</bitfield>
<bitfield>
<name>"Revision 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(xsdFileName)
Catch e As Exception
Console.WriteLine("Exception: " & e.ToString())
End Try
regDoc.Load(xmlFileName)

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:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="G2Registers">
<html>
<body>
<table border="1">
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="register">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="address"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>

using the following code:

Private Sub write_html(ByVal xml_doc As XmlDocument, ByVal xls_doc As String, ByVal html_doc As String)
Dim tfm As New Xsl.XslTransform
Dim newDoc As New IO.StringWriter
Dim xpn As System.Xml.XPath.XPathNavigator
Dim root As XmlElement = xml_doc.DocumentElement

xpn = root.CreateNavigator()

tfm.Load("..\reg_to_html.xslt", Nothing)
Dim writer As XmlTextWriter = New XmlTextWriter("..\registers.htm", Nothing)
tfm.Transform(xpn, 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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.