Migrating an Xml control using XslTransform

  • Thread starter Thread starter WT
  • Start date Start date
W

WT

Hello,

I have code created with .net 1.0 and migrated to 3.5.
Form 2.0 the XslTransform class is obsolete and the vs2008 compiler
generates warnings that these classes are absolete suggesting to use
XslCompiledTransform.
But all this was rendered using an Xml control and I can't find a way to
relate this control to an XslCompiledTransform ?

Any help appreciated to solve this migration pb.

CS
 
WT said:
I have code created with .net 1.0 and migrated to 3.5.
Form 2.0 the XslTransform class is obsolete and the vs2008 compiler
generates warnings that these classes are absolete suggesting to use
XslCompiledTransform.
But all this was rendered using an Xml control and I can't find a way to
relate this control to an XslCompiledTransform ?

Could you post the code causing the error? Do you have references to
XslTransform objects in the code behind files? You should be able to just
replace them using code like:

Dim xdoc As New XmlDocument
xdoc.LoadXml(strYourXml)
Dim xsdoc As New XslCompiledTransform()
xsdoc.Load(xsltFilePath)
Dim sw As New StringWriter
xsdoc.Transform(xdoc.CreateNavigator(), Nothing, sw)
strTransformed = sw.ToString
 
Thanks for answer, but the problem is not here it is in the usage of the Xml
control to display the page, my code is like this:
xt = new XslTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,xr);

// create the ArgList
XsltArgumentList xa = new XsltArgumentList();
XslHelper xh = new XslHelper();
xa.AddExtensionObject("urn:MyExt",xh);
AddParam(xa,"LanguageRequested",string.Empty,lang.Name);
AddParam(xa,"LanguageReturned",string.Empty,languageReturned);
AddParam(xa,"AsRequested",string.Empty,asRequested.ToString());
AddParam(xa,"Location",string.Empty,loc);
AddParam(xa,"Title",string.Empty,Title);
AddParam(xa,"Viewer",string.Empty,Request.Url.AbsolutePath);
AddParam(xa,"myRoot",string.Empty,loc.Substring(0,loc.IndexOf("/")));

// load up the Xml control
myXml.DocumentSource = filePath;
myXml.Transform = xt;
myXml.TransformArgumentList = xa;


Problem is in the last 3 lines, MS doc for Xml control speaks about some
possibility to use XslCompiledTransform for this control in place of
XslTransform but how, I spent time reading all the members and found no one
able to receive an XslCompiledTransform ?

CS
 
WT said:
Thanks for answer, but the problem is not here it is in the usage of the
Xml control to display the page, my code is like this:
xt = new XslTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,xr);

// create the ArgList
XsltArgumentList xa = new XsltArgumentList();
XslHelper xh = new XslHelper();
xa.AddExtensionObject("urn:MyExt",xh);
AddParam(xa,"LanguageRequested",string.Empty,lang.Name);
AddParam(xa,"LanguageReturned",string.Empty,languageReturned);
AddParam(xa,"AsRequested",string.Empty,asRequested.ToString());
AddParam(xa,"Location",string.Empty,loc);
AddParam(xa,"Title",string.Empty,Title);
AddParam(xa,"Viewer",string.Empty,Request.Url.AbsolutePath);
AddParam(xa,"myRoot",string.Empty,loc.Substring(0,loc.IndexOf("/")));

// load up the Xml control
myXml.DocumentSource = filePath;
myXml.Transform = xt;
myXml.TransformArgumentList = xa;


Problem is in the last 3 lines, MS doc for Xml control speaks about some
possibility to use XslCompiledTransform for this control in place of
XslTransform but how, I spent time reading all the members and found no
one able to receive an XslCompiledTransform ?

OK, so whatever myXml is has a property called Transform which accepts an
object of type XslTransform? Do you have the source code for whatever myXml
is an instance of? If so then you can change its Transform property to
accept an XslCompiledTransform and then change all the references to it to
create a compiled transform instead and pass that in.

At the end of the day, it might not be worth the effort. You would probably
spend a lot of time refactoring your code to fix something that isn't
broken. XslTransform may be deprecated, but it hasn't been removed and it
still works. If you are likely to rewrite all the controls before the next
major release of VS & the .NET framework then you might as well wait until
then.
 
The control is the asp.net standard Xml control.
I have tried something base on your code and using the DoucmentContent
property:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath);
xt = new XslCompiledTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,null,xr);
StringWriter sw = new StringWriter();
xt.Transform(xdoc.CreateNavigator(),xa,sw);
myXml.DocumentContent = sw.ToString();

need to check now.
Anyway thanks.

CS
 
Hi CS,

As for the XML control, it does be an existing issue that the 2.0 control
of ASP.NET XML doesn't correctly exposed the "Transform" property as
"XslCompiledTransform" class. This make it raise "obsolete" error when you
try perform transforming on some complex xslt template(such as the ones
that will require additional custom arguements) since such xslt will need
dynamic compilation of the XSLT transform which will raise error.

So far, I think the following code you posted (which programmtically use
XslCompiledTransform class to do the XSL transforming) is reasonable:

============
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath);
xt = new XslCompiledTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,null,xr);
StringWriter sw = new StringWriter();
xt.Transform(xdoc.CreateNavigator(),xa,sw);
myXml.DocumentContent = sw.ToString();
================

Also, on the page, you can put a ASP.NET Literal control instead of Xml
control and assign the transfored result content to the Literal control's
Text propety.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
<[email protected]>
 
Thanks Steven.
CS
Steven Cheng said:
Hi CS,

As for the XML control, it does be an existing issue that the 2.0 control
of ASP.NET XML doesn't correctly exposed the "Transform" property as
"XslCompiledTransform" class. This make it raise "obsolete" error when you
try perform transforming on some complex xslt template(such as the ones
that will require additional custom arguements) since such xslt will need
dynamic compilation of the XSLT transform which will raise error.

So far, I think the following code you posted (which programmtically use
XslCompiledTransform class to do the XSL transforming) is reasonable:

============
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath);
xt = new
XslCompiledTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,null,xr);
StringWriter sw = new StringWriter();
xt.Transform(xdoc.CreateNavigator(),xa,sw);
myXml.DocumentContent = sw.ToString();
================

Also, on the page, you can put a ASP.NET Literal control instead of Xml
control and assign the transfored result content to the Literal control's
Text propety.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
You're welcome CS.

Also, I agree that this is an serious problem that cause the ASP.NET xml
control not quite useful in new version environment. I would also suggest
you submit your comments and feedback on this so that the product team can
also hear more on this:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
In-Reply-To: <[email protected]>
Subject: Re: Migrating an Xml control using XslTransform
Date: Mon, 19 May 2008 14:47:03 +0200
Thanks Steven.
CS
"Steven Cheng [MSFT]" <[email protected]> a écrit dans le message
de news:[email protected]...
Hi CS,

As for the XML control, it does be an existing issue that the 2.0 control
of ASP.NET XML doesn't correctly exposed the "Transform" property as
"XslCompiledTransform" class. This make it raise "obsolete" error when you
try perform transforming on some complex xslt template(such as the ones
that will require additional custom arguements) since such xslt will need
dynamic compilation of the XSLT transform which will raise error.

So far, I think the following code you posted (which programmtically use
XslCompiledTransform class to do the XSL transforming) is reasonable:

============
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath);
xt = new
XslCompiledTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,null,xr);
StringWriter sw = new StringWriter();
xt.Transform(xdoc.CreateNavigator(),xa,sw);
myXml.DocumentContent = sw.ToString();
================

Also, on the page, you can put a ASP.NET Literal control instead of Xml
control and assign the transfored result content to the Literal control's
Text propety.

Sincerely,

Steven Cheng

M
 
Done.
Steven Cheng said:
You're welcome CS.

Also, I agree that this is an serious problem that cause the ASP.NET xml
control not quite useful in new version environment. I would also suggest
you submit your comments and feedback on this so that the product team
can
also hear more on this:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
In-Reply-To: <[email protected]>
Subject: Re: Migrating an Xml control using XslTransform
Date: Mon, 19 May 2008 14:47:03 +0200
Thanks Steven.
CS
"Steven Cheng [MSFT]" <[email protected]> a écrit dans le message
de news:[email protected]...
Hi CS,

As for the XML control, it does be an existing issue that the 2.0
control
of ASP.NET XML doesn't correctly exposed the "Transform" property as
"XslCompiledTransform" class. This make it raise "obsolete" error when you
try perform transforming on some complex xslt template(such as the ones
that will require additional custom arguements) since such xslt will
need
dynamic compilation of the XSLT transform which will raise error.

So far, I think the following code you posted (which programmtically use
XslCompiledTransform class to do the XSL transforming) is reasonable:

============
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath);
xt = new
XslCompiledTransform();
xslt = Server.MapPath(xslt);
XmlUrlResolver xr = new XmlUrlResolver();
xt.Load(xslt,null,xr);
StringWriter sw = new StringWriter();
xt.Transform(xdoc.CreateNavigator(),xa,sw);
myXml.DocumentContent = sw.ToString();
================

Also, on the page, you can put a ASP.NET Literal control instead of Xml
control and assign the transfored result content to the Literal
control's
Text propety.

Sincerely,

Steven Cheng

M
 
Thank you!
--------------------
From: "WT" <[email protected]>
Subject: Re: Migrating an Xml control using XslTransform
Date: Tue, 20 May 2008 12:43:40 +0200
Done.
"Steven Cheng [MSFT]" <[email protected]> a écrit dans le message
de news:[email protected]...
You're welcome CS.

Also, I agree that this is an serious problem that cause the ASP.NET xml
control not quite useful in new version environment. I would also suggest
you submit your comments and feedback on this so that the product team
can
also hear more on this:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

=
 
Back
Top