Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

XslCompiledTransform.Transform() method question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 26 Jun 2007 16:45 GMT
VS2005; .NET 2.0

I want to use the XslCompiledTransform.Transform() method for its stated
purposes.

However, I have an XmlDocument object already in memory and I can't figure
out how to use that without first saving it to disk and then referencing that
file in the Transform() method.

xslt.Load("MyXSLfile.xslt");
XMLdoc.Save("XSLTtransform.xml");
xslt.Transform("XSLTtransform.xml", "XSLTtransform.htm");
String XMLtransform = File.ReadAllText("XSLTtransform.htm");

Now I have my transformed XML into HTML string and can put it in my current
HTMLDocument. But surely there is some way to do this without reading/writing
to actual files. I just can't figure this out.

Any help?
Martin Honnen - 26 Jun 2007 16:59 GMT
> VS2005; .NET 2.0
>
[quoted text clipped - 4 lines]
> out how to use that without first saving it to disk and then referencing that
> file in the Transform() method.

There are several overloads of the Transform method that take an
IXPathNavigable as the first argument, for instance this one:
<http://msdn2.microsoft.com/en-us/library/ateytk4a.aspx>
So you can call
 xslCompiledTransformInstance(xmlDocumentInstance.CreateNavigator(), ...)
for those methods.

Then there are overloads taking an XmlReader as the first argument so
you can pass in an XmlNodeReader over your XmlDocument
 xslCompiledTransformInstance(New XmlNodeReader(xmlDocumentInstance), ...)

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Jeff - 26 Jun 2007 17:39 GMT
Hi Martin,

And thanks for your timely info.

Unfortunately, I don't understand any of that syntax or the use of the
Readers/Writers. I read the Online VS2005 help doc for this class - and I
don't get it. So, your response sounds like that doc to me. A concrete
example would go miles towards helping my mental deficit.  :)

I guess what I am asking is if my code can be rewritten without using
external files. If so, a concrete example replacing mine would help me to
understand. I seem to have some mental block.

Thanks much if you are able to provide such an example.
Martin Honnen - 26 Jun 2007 18:10 GMT
> Unfortunately, I don't understand any of that syntax or the use of the
> Readers/Writers. I read the Online VS2005 help doc for this class - and I
[quoted text clipped - 4 lines]
> external files. If so, a concrete example replacing mine would help me to
> understand. I seem to have some mental block.

Here is an example creating an IXPathNavigable using CreateNavigator,
assuming you have an XmlDocument variable named yourXmlDocumentInstance:

  Dim xsltProcessor As New XslCompiledTransform()
  xsltProcessor.Load("sheet.xslt")
  xsltProcessor.Transform(_
    yourXmlDocumentInstance.CreateNavigator(), _
    Nothing, _
    File.Open("result.html", FileMode.Create))

I posted the wrong link somehow, the link to the method overload should be
<http://msdn2.microsoft.com/en-us/library/ms163434.aspx>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Jeff - 26 Jun 2007 22:30 GMT
Hi Martin,

One step closer it appears. But aren't you still using a File for the
translated XML? e.g. "result.html"

Can't I get it back in a String?

Thanks

> > Unfortunately, I don't understand any of that syntax or the use of the
> > Readers/Writers. I read the Online VS2005 help doc for this class - and I
[quoted text clipped - 17 lines]
> I posted the wrong link somehow, the link to the method overload should be
> <http://msdn2.microsoft.com/en-us/library/ms163434.aspx>
Jeff - 26 Jun 2007 22:55 GMT
Thanks Martin.

With your example, I was able to get my base understanding of readers/writers.

Here is what worked for me.

StringWriter sw = new StringWriter();
xslt.Load("MyXSLfile.xslt");
xslt.Transform(XmlDoc.CreateNavigator(), null, sw);
// now sw.ToString() has the contents of the translated XML

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.