473,513 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.net 2 and C# - how to show results of xslt as web page?

I am using Visual Studio 2005 .NET 2.0. and C#.
Has anybody transformed xml using xsl and shown the results as a web page?

It should be a simple task.... but I can't find a way through the maze of
deprecated or incompatible classes in .NET
I have a dataset object (which has a GetXml() method which returns rows as a
xml string) that I want to transform using an xsl file. Then I want the
results in my web page. What is the best way to do this? When I copy examples
I find, I can't build because various classes are deprecated. So I replace
them with recommended alternatives and then they are incompatible.
I have tried using many different classes to do this with no success. This
is my latest attempt:

XmlDocument x = new XmlDocument();
x.LoadXml(ds.GetXml()); //ds is a Dataset object

// can't use XslTransform anymore, have to use XslCompiledTransform
XslCompiledTransform myXslTransform = new XslCompiledTransform();
myXslTransform.Load("questions.xsl");
StringWriter stringWriter = new StringWriter();
myXslTransform.Transform(x, null, stringWriter);
outputLabel.Text = stringWriter.ToString();

The ouputLabel is set to the raw xml data with the xml tags stripped and
with no transformation... not what I want. The transformation works fine when
done browser side in IE.

Rob
Aug 23 '06 #1
5 3690


imissphp wrote:
I am using Visual Studio 2005 .NET 2.0. and C#.
Has anybody transformed xml using xsl and shown the results as a web page?
You might want to use Oleg's eXml ASP.NET 2.0 control:
<http://www.xmllab.net/Products/eXml/tabid/174/Default.aspx>
XmlDocument x = new XmlDocument();
x.LoadXml(ds.GetXml()); //ds is a Dataset object
XmlDocument is overkill if you simple want to do an XSLT transformation,
you don't need it at all for the transformation.
// can't use XslTransform anymore, have to use XslCompiledTransform
XslCompiledTransform myXslTransform = new XslCompiledTransform();
myXslTransform.Load("questions.xsl");
StringWriter stringWriter = new StringWriter();
myXslTransform.Transform(x, null, stringWriter);
myXslTransform.Transform(XmlReader.Create(new
StringReader(ds.GetXml())), null, stringWriter);
outputLabel.Text = stringWriter.ToString();

The ouputLabel is set to the raw xml data with the xml tags stripped and
with no transformation... not what I want.


Can you provide a minimal XML and XSLT stylesheet? It is hard to guess
where things go wrong without seeing the details. What kind of object is
outputLabel?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 23 '06 #2

"imissphp" <im******@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
>I am using Visual Studio 2005 .NET 2.0. and C#.
Has anybody transformed xml using xsl and shown the results as a web page?

It should be a simple task.... but I can't find a way through the maze of
deprecated or incompatible classes in .NET
I have a dataset object (which has a GetXml() method which returns rows as
a
xml string) that I want to transform using an xsl file. Then I want the
results in my web page. What is the best way to do this? When I copy
examples
I find, I can't build because various classes are deprecated. So I replace
them with recommended alternatives and then they are incompatible.
I have tried using many different classes to do this with no success. This
is my latest attempt:

XmlDocument x = new XmlDocument();
x.LoadXml(ds.GetXml()); //ds is a Dataset object

// can't use XslTransform anymore, have to use XslCompiledTransform
XslCompiledTransform myXslTransform = new XslCompiledTransform();
myXslTransform.Load("questions.xsl");
StringWriter stringWriter = new StringWriter();
myXslTransform.Transform(x, null, stringWriter);
outputLabel.Text = stringWriter.ToString();

The ouputLabel is set to the raw xml data with the xml tags stripped and
with no transformation... not what I want. The transformation works fine
when
done browser side in IE.
This sounds like your transform didn't work. Have you tried debugging it?
You can set breakpoints and everything. Just open it in VS.NET 2005, set
breakpoints, attach to aspnet_wp (or w3wp) and go.

John
Aug 23 '06 #3
Thanks for your response John.
Sorry I'm new to VS.NET 2005, what is aspnet_wp and what do you mean by
attaching it? I have set breakpoints and inspected the objects but can't see
the transformation taking place, ie. I can't see the results as a property of
any of the objects, except the raw data in the stringWriter.

Rob

"John Saunders" wrote:
>
This sounds like your transform didn't work. Have you tried debugging it?
You can set breakpoints and everything. Just open it in VS.NET 2005, set
breakpoints, attach to aspnet_wp (or w3wp) and go.

John
Aug 24 '06 #4
"imissphp" <im******@discussions.microsoft.comwrote in message
news:73**********************************@microsof t.com...
Thanks for your response John.
Sorry I'm new to VS.NET 2005, what is aspnet_wp and what do you mean by
attaching it? I have set breakpoints and inspected the objects but can't
see
the transformation taking place, ie. I can't see the results as a property
of
any of the objects, except the raw data in the stringWriter.

Rob

"John Saunders" wrote:
>>
This sounds like your transform didn't work. Have you tried debugging it?
You can set breakpoints and everything. Just open it in VS.NET 2005, set
breakpoints, attach to aspnet_wp (or w3wp) and go.
An ASP.NET web application is hosted inside of a worker process. On Windows
XP, this process is called aspnet_wp. On Windows Server 2003, this is called
w3wp.

The "normal" way to debug a program is to press "F5". Another way is to
attach to the process in question. Use Tools->Attach to Process and select
the worker process. Click Attach and make sure that "Managed" is checked.

Now, just set breakpoints on your ASP.NET source code. In particular, you
might want to set a breakpoint before you call the transform. Then open the
stylesheet in VS.NET, and set a breakpoint, just as though it were a C#
program. A good place to stop is inside of your <xsl:template match="/">.
You can single-step, step into templates, view variables, etc.
Caveat: I have used the attach technique on ASP.NET applications, and I have
single-stepped through transforms. I have not done both at the same time, so
it's possible that part won't work. In that case, see if you can open the
stylesheet in VS.NET, and specify a sample XML file for it to work on in the
stylesheet's properties. You will then be able to set breakpoints,
single-step, etc.

Good luck,
John
Aug 24 '06 #5
I think you need to have the StringWriter actually be writing to
something else, in my case I use a StringBuilder.
>Yours
myXslTransform.Load("questions.xsl");
StringWriter stringWriter = new StringWriter();
myXslTransform.Transform(x, null, stringWriter);
outputLabel.Text = stringWriter.ToString();
>Mine
StringBuilder SB = new StringBuilder();
Xsl.XslCompiledTransform xslt = new
Xsl.XslCompiledTransform();
xslt.Load(MyStyle);

using (TextWriter text = new StringWriter(SB))
{
xslt.Transform(MyUrl, null, text);
}

This works just great for me, plus the bonus of the "using" syntax
which makes sure that everything gets closed and disposed when done.
Uh, I forget where I read about that part, maybe the C# cookbook...

Anna

imissphp wrote:
Thanks for your response John.
Sorry I'm new to VS.NET 2005, what is aspnet_wp and what do you mean by
attaching it? I have set breakpoints and inspected the objects but can't see
the transformation taking place, ie. I can't see the results as a property of
any of the objects, except the raw data in the stringWriter.

Rob

"John Saunders" wrote:

This sounds like your transform didn't work. Have you tried debugging it?
You can set breakpoints and everything. Just open it in VS.NET 2005, set
breakpoints, attach to aspnet_wp (or w3wp) and go.

John
Aug 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1282
by: Neal | last post by:
I have a simple survey with a drop down that lets users select different depts in our organization. Displaying the results to a different page works fine, but I would like to create another, same...
4
7180
by: Michael | last post by:
Hi, I create site with a prefix FramSet layout. The main page contains HTML <Form> function like this <Form name=my_form method=post action=my_action.asp> <input name=search_string ...
0
1413
by: thomas | last post by:
Hi all, I was wandering is anyone can help. When I click on the 'view all' link on my homepage http://www.guitarmidi.co.uk I woild like to output the first 20 results on screen then have a...
3
2192
by: DLN | last post by:
I want to create a form page that has a single field on it, say "last name", and when that last name is entered in, I want to click a button and have it bring up another page with the results. Any...
3
1163
by: Mark Goldin | last post by:
I need to show results of transformation on the server. Thansformation returns an attribute based xml string. Can I bind DataRepeater to the xml string? Thanks
0
1391
by: tom | last post by:
Hi all, I'm having a bit of trouble getting my site to output a certain number of results per page. Any help on this would be greatly appriciated. Without this function my code outputs all...
1
1026
by: Dominique | last post by:
Hi, I'd like to show an html page in a form but without use the webform control because I can't create my own context menu detecting the link right click, and so on ... Does any one have an...
1
2106
by: blondieUA | last post by:
Hello guys! I have some problem with creating the result page :( I need to create a web-page for my college course in Computer Science. I decided to create a site about Horoscopes. So if a...
2
2641
by: Steve Luk | last post by:
Let me start by saying I'm a newbie to this .Net development and I'm currently assigned to crack into an old ASP.NET v1.134 website source to rebuild it. The website is part of a solution consisting...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
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
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
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
7519
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...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.