Xml WebControl's Transform property in ASP.NET 2.0

N

n33470

We're in the process of migrating our projects to use VS2005 from
VS2003. We have a web page that uses the XML WebControl
(System.Web.UI.WebControls.Xml) to perform an XSLT tranformation by
using the property "Transform" of the webcontrol. Here is a sample:

xmlMessage.Transform = _app.Cache.UserMessagesXsltUser;

'xmlMessage' is the XML Web Control, and
'_app.Cache.UserMessagesXsltUser' is the transformation to apply.

In .NET 1.1, the class of the transformation was XslTransform.
In .NET 2.0 this class has been deprecated by the new
XslCompiledTransform class. However, the Xml Web control's
'Transform' property still takes an object of type 'XslTransform',
instead of the new class of 'XslCompiledTransform'.

How do I migrate the Xml web control's Transform property in .NET 2.0?
Is there a new version of the Xml Web Control with a Transform property
that takes an object of type XslCompiledTransform?

Thanks!


--steve
 
K

Kevin Spencer

I have lots of them, but not enough time to implement many of them.

I also have an idea that this refers to something you posted earlier,
perhaps in this thread. But my newsreader hides read messages, and it's too
much trouble for me to go looking for it.

;-)

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
N

n33470

Kevin,

I'm lost, what are you getting at? I cross-posted the same question on
microsoft.public.dotnet.framework.aspnet.webcontrols, is that what
you're talking about? At any rate, the question is still unanswered.

I'm surprised that if the XslTransform class is being deprecated in
..NET 2.0 by the XslCompiledTransform class, that the XML webcontrol's
'Transform' property (System.Web.UI.WebControls.Xml) does not at least
provide an overload to call it with new class.

I'm not asking you to provide with sample code, or implement any sort
of solution, just give me a pointer in the right direction.

In the meantime, I'm trying to refactor our code to get rid of the use
of the Xml webcontrol, and perform the transformation manually.

--steve
 
K

Kevin Spencer

Hi steve,
I'm surprised that if the XslTransform class is being deprecated in
.NET 2.0 by the XslCompiledTransform class, that the XML webcontrol's
'Transform' property (System.Web.UI.WebControls.Xml) does not at least
provide an overload to call it with new class.

As to why it is being deprecated, read the following article from the msdn2
online library:

http://msdn2.microsoft.com/en-us/library/66f54faw.aspx

Why the "Transform" property is not overloaded, I can't say. I don't know
all the inner workings of the XML WebControl. It does seem like a good idea.
At any rate, the following msdn2 article indicates that you can use an
XslCompiledTransform class to format the XML, and how to do it:

http://msdn2.microsoft.com/en-us/library/782szw84(en-US,VS.80).aspx

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
G

Guest

Im having the same problem and I think this may be a bug. If you look at the
documentation for the Xml control it says:

"You can format the XML document with a System.Xml.Xsl.XslCompiledTransform
object or with an XSL Transformation style sheet file by setting the
appropriate property."


Not that it says XslCompiledTransform, but the Transform property is if Type
XslTransform.

Basically anybody that uses this control is screwed because you will get
errors telling you to use the XslCompiledTransform but the Transform property
only takes an XlsTransform.

What is the workaround?
 
N

n33470

The workaround for me was to get rid of the Xml web control completely.
Since we're just using it to transform an xml doc to html and then
dump the contents on a web page, I replaced the Xml web control with a
simple Literal control. Then, I just programmatically transform the
xml doc and put the result of the transformation (which for us is raw
html) into the literal.

Something like this (where doc is XmlDocument, litUserMessages is the
literal):

System.Text.StringBuilder sb = new System.Text.StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new
System.IO.StringWriter(sb));
myTransform.Transform(doc, null, writer);
litUserMessages.Text = sb.ToString();

--steve
 
N

n33470

The workaround for me was to get rid of the Xml web control completely.
Since we're just using it to transform an xml doc to html and then
dump the contents on a web page, I replaced the Xml web control with a
simple Literal control. Then, I just programmatically transform the
xml doc and put the result of the transformation (which for us is raw
html) into the literal.

Something like this (where doc is XmlDocument, litUserMessages is the
literal):

System.Text.StringBuilder sb = new System.Text.StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new
System.IO.StringWriter(sb));
myTransform.Transform(doc, null, writer);
litUserMessages.Text = sb.ToString();

--steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top