xslt, multiple transforms

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

Can anyone provide a good example of the simplest way to do multiple
transformations on an xml file? I start out with an xml string and three
physical xslt files, and want to transform the xml using all three
stylesheets, one at a time, and end up with a result xml string.

All the examples I can find have the xml being written to a physical file
every time, and this is not what I want. I can use an in-memory xmlwriter
or xmldocument if that will simplify things.
 
First of all create an XslTransform instance. Then load the XSLT
document (Load()). After that you can apply a transformation to for
example an XmlDocument, by calling Transform(yourDocument,
myXsltArgumentList, output). Some of the allowed outputs are a
textwriter and a stream. This allows you to both write to a
MemoryStream or for example a StringWriter. After you applied a
transformation, you can use both the stream or the string as an input
for your new xml document (XmlDocument.Load and XmlDocument.LoadXml are
relevant).
 
This is what I'm trying. I'm still relatively unfamiliar with the Stream
objects, so I'm probably just not understanding how to properly extract the
xml text out to re-use in my next transformation. What method(s) could I
use here?
 
Once you got the result in a memory stream, you can load it in a new
XML document. You can use that new document for your next
transformation. You can do this as many times as you want.

It should look something like:
MemoryStream outputStream = new MemoryStream();
myTransformer.Transform(inputDoc, args, outputStream);

XmlDocument outputDoc = new XmlDocument();
outputDoc.Load(outputStream);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top