Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : A couple of newbie xsl conversion of xml to html questions (C#/.Net)


Michael Howes
4/29/2005 1:00:56 PM
I have some xml data that I want to turn into an html report.
I wrote some xsl (my first xsl) and tested it in XMLSpy. It transformed my
xml to html pretty much how I wanted (I'm still trying to understand table
formatting, like table width in xsl, my tables aren't as wide as I'm
specifying).

I want to use this transform in my c#/winforms/.net application

I loaded some sample xml using XmlDocument
Created an XPathNavigaor
Loaded the xsl into XslTransform
and used a XmlTextWriter along with XslTranform to write the html

I have a handful of newbie questions
a. The resulting html won't render in a browser but it will render in
Dreamweaver
My guess is because of the inital "header" that's written which is
<html xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">

there isn't info written like
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

How is this intial html info being written and is there a way to control
that from xsl?

b. The html doesn't have any CR or LF how can I get the
XMLTextWriter/XslTransform to format the html better?

c. I'm just doing proof of concept right now, so I'm reading the sample xml
from a file but in reality I will be creating the xml at the time I'm going
to also be transforming it. Is there a way to use something like
XmlTextWriter (and get the XmlDocument??) with the xml in it since I'll be
using XmlTextWriter to build and write the xml

thanks
mike


Martin Honnen
4/30/2005 12:00:00 AM


[quoted text, click to view]


[quoted text, click to view]

You can use
<xsl:output method="html" version="4.01"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
indent="yes" />
As for the namespaces you can use
<xsl:stylesheet
exclude-result-prefixes="fn xdt xs"
...>
to prevent them from appearing in the output.


[quoted text, click to view]

See above, the indent="yes" should help.

[quoted text, click to view]

I am not sure what the problem is, the Load method of an XmlDocument
instance takes an Xml(Text)Reader:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassLoadTopic4.asp>

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button