473,480 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XslCompiledTransform procudes different results from XslTransform

1 New Member
Here is the code you can past in your console application to see the differences. I need to know how to get this to work correctly.
Expand|Select|Wrap|Line Numbers
  1. #pragma warning disable // because we are using a depricated object 
  2. static void Main(string[] args) 
  3. /* 
  4. * There are two problems: 
  5. * 1. The characters (CRLF) are not being output by the new object. 
  6. * 2. Anything not in xml tags causes a crlf to be inserted. 
  7. */ 
  8.  
  9. // xsl file 
  10. string xsltFile = @"<?xml version=""1.0"" encoding=""iso-8859-1""?><xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" xmlns:msxsl=""urn:schemas-microsoft-com:xslt"" xmlns:user=""urn:my-scripts""><xsl:strip-space elements=""*""/><xsl:output method=""text"" encoding=""ISO-8859-1"" indent=""no"" /><xsl:preserve-space elements=""line"" /><xsl:template match=""/root/lines/line"">
  11. <xsl:choose> 
  12. <xsl:when test=""substring(., 14, 1) = '2'""><xsl:value-of select=""."" /> </xsl:when><!-- this crlf is ignored --> 
  13. <xsl:when test=""substring(., 14, 1) = '3'""><xsl:value-of select=""."" />This text causes the crlf to be applied in the new object. </xsl:when> <!-- this crlf is not ignored because text is by it.--> 
  14. <xsl:when test=""substring(., 14, 1) = '4'""><xsl:value-of select=""."" />This text has no crlf as behaves as expected.</xsl:when><!-- this does not have a crlf and acts correctly--> 
  15. <xsl:otherwise><xsl:value-of select=""."" /> </xsl:otherwise> 
  16. </xsl:choose> 
  17. </xsl:template></xsl:stylesheet>"; 
  18.  
  19. // input test file 
  20. string inputFileAsci = 
  21. @"<?xml version=""1.0"" encoding=""ISO-8859-1""?><root><lines> 
  22. <line>This is test 1</line> 
  23. <line>This is test 2</line> 
  24. <line>This is test 3</line> 
  25. <line>This is test 4</line> 
  26. <line>This is test 5</line> 
  27. </lines></root>"; 
  28.  
  29. System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); 
  30. byte[] input = encoding.GetBytes(inputFileAsci); 
  31.  
  32. // old object 
  33. System.Xml.Xsl.XslTransform transform1 = new System.Xml.Xsl.XslTransform(); 
  34. transform1.Load(new XmlTextReader(new StringReader(xsltFile)), new XmlUrlResolver()); 
  35. MemoryStream ms1 = new MemoryStream(input, 0, input.Length); 
  36. XPathDocument doc1 = new XPathDocument(ms1); 
  37. MemoryStream output1 = new MemoryStream(); 
  38. transform1.Transform(doc1, null, output1); 
  39. Console.WriteLine("GOOD - Original XslTransform Object"); 
  40. Console.Write(encoding.GetString(output1.ToArray() )); 
  41.  
  42. Console.WriteLine(); 
  43.  
  44. // new object 
  45. XslCompiledTransform transform2 = new System.Xml.Xsl.XslCompiledTransform(); 
  46. XsltSettings settings = new XsltSettings(true, true); 
  47. transform2.Load(new XmlTextReader(new StringReader(xsltFile)), settings, new XmlUrlResolver()); 
  48. MemoryStream ms2 = new MemoryStream(input, 0, input.Length); 
  49. XmlTextReader doc2 = new XmlTextReader(ms2); 
  50. MemoryStream output2 = new MemoryStream(); 
  51. transform2.Transform(doc2, null, output2); 
  52. Console.WriteLine("BAD - New XslComiledTransform Object"); 
  53. Console.WriteLine(encoding.GetString(output2.ToArr ay())); 
  54.  
  55. Console.Read(); 
  56.  
  57.  
Sep 4 '08 #1
0 1224

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4168
by: Eckhard Schwabe | last post by:
when switching from the old "XslTransform " to "XslCompiledTransform" I notice a difference in the handling of whitespace. I need to transform a XML file which contain tabs (\t), and which remain...
0
1194
by: Matt | last post by:
With VS2005 I see that the XslTransform class has been deprecated and XslCompiledTransform has replaced it. I am having issues with trying to get the new class to work how it did with the old. I...
1
2572
by: Steve | last post by:
Using VB.NET 2.0 I have a simple routine that attempts transforms an XmlDocument with an XSLT stylesheet into HTML. Under the old 1.1 framework with XslTransform, everything worked fine. Now...
6
8073
by: W. Jordan | last post by:
Hello there, Are there anybody who is using the XslCompiledTransform that comes with .net framework, which was said to be a replacement of the XslTransform class? I found that the class has...
1
496
by: Sunday Oke | last post by:
Hi folks I have this code which basically transforms a recordset retrieved from a oracle database. With the XslTransform class being deprecated I have tried to use the XslCompiledTransform class...
12
10056
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
3
5419
by: Andy Fish | last post by:
Hi, From reading the documentation, I get the impression that XslCompiledTransform should be faster than XslTransform on my test with a large complex document and a large complex XSLT, the...
2
3425
by: steve.nickels | last post by:
Hello. I'm in the midst of moving a web application from ASP.NET 1.1 to ASP.NET 2.0 (framework 3.0), and as part of this move, I am told by Visual Studio that the XslTransform object is now...
1
1626
by: =?Utf-8?B?Vmlub2Q=?= | last post by:
Hi, I am having a problem doing the transform. Actually i am migrating the code from XslTranform class into XslCompiledTransform class. Here is the code that i am using in .net 1.1 private...
0
7048
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
7088
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
6741
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
6956
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
5342
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
4783
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
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.