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" ?>
<name>Version Register</name>
<name>"Xilinx Part"</name>
<name>"Revision Number"</name>

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
Catch e As Exception
Console.WriteLine("Exception: " & e.ToString())
End Try

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="">
<xsl:template match="G2Registers">
<table border="1">
<xsl:template match="register">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="address"/></td>

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:


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

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.