473,394 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 4789
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.