Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : XSLT, coming from ASP model


Eric Phetteplace
6/14/2004 9:24:26 AM
Hello,

I am moving over from using msxml2.domdocument to system.xml and
system.xml.xsl.

I'd like to present this to my group today, so your help is appreciated.

I want to transform an XML object (built on the fly) with an XSL document
(URL to document) and have it return a string object for my function.

Here's where I am:

Function x as String
'this function will return transformed xml
Dim oXML as New System.xml.xmldocument
oXML.LoadXML("<document/>")

oXSL as New System.xml.xmldocument
oXSL.Load([stylesheet])

x = ???
End Function

I started down the path of creating an XMLReader class, and I was going to
"read" that into x. Am I on the right track?

Your help is appreciated,

Eric

Eric Phetteplace
6/14/2004 12:25:45 PM
Thanks Oleg, that's what I needed.

However, when I try to compile, (forgive the paraphrasing, as I'm not in
front of my .NET machine) I get an error saying there isn't a Transform
method with these parameter types. There are 18 definitions of the
Transform method. I had to use chr(0) in place of the NULL keyword, since
there is no NULL in VB.NET.

Perhaps it doesn't recognize my null? System.DBNull didn't help. Perhaps
it's the XMLDocument?

Eric


[quoted text, click to view]

Oleg Tkachenko [MVP]
6/14/2004 4:52:49 PM
[quoted text, click to view]

No, that's MSXML model. In .NET you better use the following (C# code):

XmlDocument doc = new XmlDocument();
//Build it
doc.LoadXml("<doc/>");
XslTransform xslt = new XslTransform();
//Load stylesheet (you should use here Server.MapPath in ASP.NET)
xslt.Load("whatever.xsl");
StringWriter sw = new StringWriter();
//Run transformation
xslt.Transform(doc, null, sw, null);
sw.Close();
return sw.ToString()

Additionally consider caching compiled XslTransform object for
repetitive transformations.
--
Oleg Tkachenko [XML MVP]
Oleg Tkachenko [MVP]
6/14/2004 9:37:49 PM
[quoted text, click to view]

Hmm. Which .NET version are you using? There is a difference in
XslTransform API between .NET 1.0 and 1.1. I meant the following method:

[Visual Basic] Overloads Public Sub Transform(IXPathNavigable,
XsltArgumentList, TextWriter, XmlResolver)
[C#] public void Transform(IXPathNavigable, XsltArgumentList,
TextWriter, XmlResolver);

XmlDocument is IXPathNavigable and StringWriter is TextWriter.

[quoted text, click to view]

It's Nothing as far as I know. in VB.NET you should have something like

xslt.Transform(doc, Nothing, sw, Nothing)

--
Oleg Tkachenko [XML MVP]
Eric Phetteplace
6/15/2004 8:40:18 AM
Using 'Nothing' in place of 'null' solved the problem.

Thanks again Oleg. You've been most helpful.

Regards,

Eric Phetteplace

"Oleg Tkachenko [MVP]" <oleg@no_!spam!_please!tkachenko.com> wrote in
message news:OYFYx6jUEHA.3140@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button