471,305 Members | 1,026 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

Dynamic xslt and transform with-out System.IO

Anyone know if there is a way to dynamicly create a Xslt template/s and use
them as an
xml transform with-out use files for the Xslt?

All the methods I see use files.

I want to create a Xslt transform via code?

Any examples would be great.

Thanks,

Schneider
Nov 12 '05 #1
4 4611
schneider wrote:
Anyone know if there is a way to dynamicly create a Xslt template/s and use
them as an
xml transform with-out use files for the Xslt?

All the methods I see use files.

I want to create a Xslt transform via code?


Basically any XSLT stylesheet is just XML document, so of course you can
build it in-memory using XmlDocument. Another common approach is to
generate XSLT stylesheets on the fly using XSLT (again - as XSLT is XML,
the best way to generate/transform it is XSLT itself).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
So you are saying to create a xslt with a XmlDocument object?

I still don't see any way to create a XslTransform from a XmlDocument?

Have any sample code?

Thanks,

Schneider

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
schneider wrote:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an
xml transform with-out use files for the Xslt?

All the methods I see use files.

I want to create a Xslt transform via code?


Basically any XSLT stylesheet is just XML document, so of course you can
build it in-memory using XmlDocument. Another common approach is to
generate XSLT stylesheets on the fly using XSLT (again - as XSLT is XML,
the best way to generate/transform it is XSLT itself).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
You would have to first load the XSLT document into an XmlDocument object.
XmlDocument xsltDoc = new XmlDocument();
xsltDoc.LoadXml(xsltString);
Then, create an XslTransform and, now, load the XSLT document into the
transform by creating an XPathNavigator from the document:
XslTransform transform = new XslTransform();
transform.Load(xsltDoc.CreateNavigator(), null, null);
Assuming you have the XML document loaded into a XmlDocument as well,
you are now ready to perform the transformation.
Let's use a System.IO.MemoryStream as the output channel.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
XsltArgumentList args = new XsltArgumentList();
MemoryStream output = new MemoryStream(100000);
// Put any XSLT transform parameters into 'args' here.
transform.Transform
(xmlDoc.CreateNavigator(), args, output, null);

All this can be done in RAM without a single read/write to the hard drive.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"schneider" <00**@0000.SPAM> wrote in message
news:eF**************@TK2MSFTNGP15.phx.gbl...
So you are saying to create a xslt with a XmlDocument object?

I still don't see any way to create a XslTransform from a XmlDocument?

Have any sample code?

Thanks,

Schneider

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
schneider wrote:
> Anyone know if there is a way to dynamicly create a Xslt template/s and use > them as an
> xml transform with-out use files for the Xslt?
>
> All the methods I see use files.
>
> I want to create a Xslt transform via code?


Basically any XSLT stylesheet is just XML document, so of course you can
build it in-memory using XmlDocument. Another common approach is to
generate XSLT stylesheets on the fly using XSLT (again - as XSLT is XML,
the best way to generate/transform it is XSLT itself).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


Nov 12 '05 #4
schneider wrote:
So you are saying to create a xslt with a XmlDocument object?

I still don't see any way to create a XslTransform from a XmlDocument?


Hmmm, I really wonder why... Have you looked at XslTransform.Load() methods?
There is probably something wrong with the API as you (and you arent'
the first one) can't see that XmlDocument implements IXPathNavigable and
you can just pass XmlDocument instance into the XslTransform.Load() method.

It's as as simple as:

XslTransform xslt = new XslTransform();
xslt.Load(doc);

In .NET 1.1 you'll get compiler warning that you have to pass an
evidence, so use
xslt.Load(doc, null, null);

or

xslt.Load(doc, new XmlUrlResolver(),
Assembly.GetExecutingAssembly().Evidence);

if you need a URI resolving during stylesheet's load (e.g. you are using
xsl:include/xsl:import).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gary Huntress | last post: by
2 posts views Thread by Aaron Clauson | last post: by
2 posts views Thread by darrel | last post: by
2 posts views Thread by naijacoder naijacoder | last post: by
3 posts views Thread by Andrew Jocelyn | last post: by
2 posts views Thread by Patrick | last post: by
1 post views Thread by =?Utf-8?B?U0FM?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.