By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Dynamic XSL transformation

P: n/a
Hi,
I'm facing a annoying problem.
In the old ASP times, I was able to construct dynamically an XSL file
and then apply it to my XML file to create the HTML output.
Today, with the .NET framework, I can't find how to do this.
Of course, if my XSL file is already existing in my disk, it's easy
as:
/////
XPathDocument doc = new
XPathDocument(Server.MapPath("XML/Customers.xml"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("XSLT/Customers.xslt"));
StringWriter sw = new StringWriter();
trans.Transform(doc,null,sw,null);
this.txtStringBuilder.Text = sw.ToString();
sw.Close();
///
But how can I apply a transformation base on an XSL memory created
file?
Thx & regards
Phil
Nov 11 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You can generate XSL in string and load XslTransform from this string.
string xslText = "<foo xsl:version='1.0' xmlns:xsl='...' />";
XslTransform trans = new XslTransform();
trans.Load(StreangReader(xslText));

Note: loading stylesheet is a expensive. So if performance is important in
this case, I'd recommend you to cache loaded stylesheets.

Sergey
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"PHILIPPE" <Ph************@voila.fr> wrote in message
news:43**************************@posting.google.c om...
Hi,
I'm facing a annoying problem.
In the old ASP times, I was able to construct dynamically an XSL file
and then apply it to my XML file to create the HTML output.
Today, with the .NET framework, I can't find how to do this.
Of course, if my XSL file is already existing in my disk, it's easy
as:
/////
XPathDocument doc = new
XPathDocument(Server.MapPath("XML/Customers.xml"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("XSLT/Customers.xslt"));
StringWriter sw = new StringWriter();
trans.Transform(doc,null,sw,null);
this.txtStringBuilder.Text = sw.ToString();
sw.Close();
///
But how can I apply a transformation base on an XSL memory created
file?
Thx & regards
Phil

Nov 11 '05 #2

P: n/a
If your XSLT stylesheet is in a string then you can do

trans.Load(new XmlTextReader(new StringReader(xsltString)));

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"PHILIPPE" <Ph************@voila.fr> wrote in message
news:43**************************@posting.google.c om...
Hi,
I'm facing a annoying problem.
In the old ASP times, I was able to construct dynamically an XSL file
and then apply it to my XML file to create the HTML output.
Today, with the .NET framework, I can't find how to do this.
Of course, if my XSL file is already existing in my disk, it's easy
as:
/////
XPathDocument doc = new
XPathDocument(Server.MapPath("XML/Customers.xml"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("XSLT/Customers.xslt"));
StringWriter sw = new StringWriter();
trans.Transform(doc,null,sw,null);
this.txtStringBuilder.Text = sw.ToString();
sw.Close();
///
But how can I apply a transformation base on an XSL memory created
file?
Thx & regards
Phil

Nov 11 '05 #3

P: n/a
Hello!

Now that we're talking about the importance of caching XSLT stylesheets, I
was wondering if any of you know whether the XML control provided by ASP.NET
keeps an internal cache of the loaded XSLT stylesheet?

It seems like they're setting a cachedependency on the physical XSLT
stylesheet (file), but I haven't investigated this. An easy way to check
this could be to display all keys in the Cache .. and see if anything
changes!

Ideas? :-)

--
venlig hilsen / with regards
anders borum
--
Nov 11 '05 #4

P: n/a
Anders Borum wrote:
Now that we're talking about the importance of caching XSLT stylesheets, I
was wondering if any of you know whether the XML control provided by ASP.NET
keeps an internal cache of the loaded XSLT stylesheet? Yes, it does.
It seems like they're setting a cachedependency on the physical XSLT
stylesheet (file), but I haven't investigated this. An easy way to check
this could be to display all keys in the Cache .. and see if anything
changes!

They cache both XML and XSL, but they cache them in the internal cache.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #5

P: n/a
"SQL Server Development Team" <sq****@microsoft.com> wrote in message news:<#9*************@tk2msftngp13.phx.gbl>...
If your XSLT stylesheet is in a string then you can do

trans.Load(new XmlTextReader(new StringReader(xsltString)));

Thx Both, I'm going to give it a try.
Ciao
Phil
Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.