472,958 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 4758
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gary Huntress | last post by:
Hi, I'm having trouble with an xslt transform. I'm trying to transform a vector into an array of width N. For example here is my vector: <data> <x id="1">1.2</x> <x id="2">.2</x> <x...
2
by: Aaron Clauson | last post by:
Hi, I just tried to run a piece of code working with .Net 1.0 after compiling it with 1.1. It failed and I tracked it down to the XSLT transform method outputting invalid XML. The problem only...
2
by: darrel | last post by:
On my page right now, I call a function: <%=getMenu()%> in my codebehind, I have the function do an xslt transformation: sub xslt.Transform(doc, xslArg, Response.Output, Nothing) end sub
1
by: Dan Beanweed | last post by:
I have this xslt : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="p" select="'q'"/> <xsl:output...
2
by: naijacoder naijacoder | last post by:
Hi All, Any ideas on how to create a dynamic TreeView Menu with user roles.For example binding XML to Treeview or populated from DataBase.. Thx *** Sent via Developersdex...
3
by: Andrew Jocelyn | last post by:
Hi Is there a way of outputting some xml tags during an XSLT transform? For example when I use the 'xsl:value-of select="xhtml"' statement I'd like to output the children of 'xhtml' after the...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
6
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
2
by: Patrick | last post by:
Back again for another question. I have a form that I want to pass one value to an xsl file to use when the xml is displayed. I have been told that I have to pass the value to php and then do a...
1
by: =?Utf-8?B?U0FM?= | last post by:
Hi, Does anyone have any sample code they did in which they created a dynamic XSLT at runtime? I've seen many examples on the web in which an Embedded xsl:stylesheet is transformed in the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.