473,545 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make XslCompiledTran sform transform &amps; as XslTransform does

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 > b)
.....

// xsl contents
abc.aspx?p1=v1& amp;p2=<xsl:val ue-of select="$v2" />

However, since we switched to replace XslTransform with XslCompiledTran sform, all these entity classes need to be wrapped within xsl:text with DOE
<xsl:text disable-output-escaping="yes">

Results from XslTransform
if (a b)
....
abc.aspx?p1=v1& p2=...

Results from XslCompiledTran sform without be wrapped within xsl:text without doe
if (a &gt; b)
....
abc.aspx?p1=v1& amp;p2=...

In our implementations , all the XML contents were "converted into XpathDocument, and the output method of xsl file is set to "html" and I have tried to use 1- StringWriter, 2- XmlWritter, 3- MemoryStream (see below), and we got the same results from all three approaches

Is there a way that we can make the XslCompiledTran sform handle those entity classes, e.g. &amp;, &gt;, &lt; , as XslTransform
// using StringWriter version
public static string Transform(Syste m.Xml.XPath.XPa thNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );

XslCompiledTran sform xt = PrepareCompiled Transform(xslPa th, resolver);
xt.Transform(na v, PrepareXsltArgu mentList(htArgu ments), sw);
sw.Close();
xt = null;
return sb.ToString();
}
// using xml writer
public static string Transform(Syste m.Xml.XPath.XPa thNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );

XslCompiledTran sform xt = PrepareCompiled Transform(xslPa th, resolver);
XmlWriterSettin gs settings = xt.OutputSettin gs.Clone();
settings.CheckC haracters = false;
settings.CloseO utput = true;
XmlWriter xw = XmlWriter.Creat e(sb, settings);
xt.Transform(na v, PrepareXsltArgu mentList(htArgu ments), xw);
xw.Close();
sw.Close();
return sb.ToString();
}
// using memory stream
public static string Transform(Syste m.Xml.XPath.XPa thNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
// use memroystream
MemoryStream mry = new MemoryStream();
StreamReader sr = new StreamReader(mr y, System.Text.UTF 8Encoding.UTF8) ;

XslCompiledTran sform xt = PrepareCompiled Transform(xslPa th, resolver);
xt.Transform(na v, PrepareXsltArgu mentList(htArgu ments), mry);

mry.Position = 0;
string s = sr.ReadToEnd();
sr.Close();
return s;

}
private static XslCompiledTran sform PrepareCompiled Transform(strin g xslPath, XmlResolver stylesheetResol ver )
{
bool bEnableDebug = false;
XslCompiledTran sform xt = new XslCompiledTran sform(bEnableDe bug);

XsltSettings settings = new XsltSettings();
settings.Enable DocumentFunctio n = true;
XmlResolver theResolver = (stylesheetReso lver == null ? new XmlUrlResolver( ) : stylesheetResol ver);
xt.Load(GetXmlF ilePath(xslPath ), settings, theResolver);
return xt;
}

Nov 6 '06 #1
12 10069
Hi,

The disable-output-escaping is in a gray area

From the XSLT 1.0 Spec http://www.w3.org/TR/xslt#disable-output-escaping:

"Since disabling output escaping may not work with all XSLT processors and
can result in XML that is not well-formed, it should be used only when there
is no alternative."

So an XSLT processor is not required to support d-o-e.

In this case, you can try to use a StreamWriter to write out the results.

Please check the following links for more information about this issue.

http://msdn2.microsoft.com/en-us/lib...k9(VS.80).aspx
http://www.thescripts.com/forum/thread534528.html
http://forums.microsoft.com/MSDN/Sho...72483&SiteID=1

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 6 '06 #2
InvalidLastName wrote:
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)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"an d output into Stream or TextWriter.

// xsl contents
abc.aspx?p1=v1& amp;p2=<xsl:val ue-of select="$v2" />
In HTML & in links must be escaped as &amp; Don't put efforts in
producing malformed HTML.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 6 '06 #3
Thank for the reply.

However, Firefox has trouble to recognize &amp; in the link as &. All our parameters in the QueryString are returned as amp;p1 instead of p1

"Oleg Tkachenko [MVP]" <so**@body.comw rote in message news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
InvalidLastName wrote:
>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)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"an d output into Stream or TextWriter.

>// xsl contents
abc.aspx?p1=v1 &amp;p2=<xsl:va lue-of select="$v2" />
In HTML & in links must be escaped as &amp; Don't put efforts in
producing malformed HTML.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 6 '06 #4
Hi Kevin,
I am not try to use d-o-e with XslCompiledTran sform. However, since the
behavior changed, I have to use d-o-e to make sure XslCompiledTran sform
generate HTML all the browsers can process. IE has no problem to read some
thing like

a.aspx?p1=v1&am p;p2=v1&amp;p3= v3

IE return
p1
p2
p3
in QueryString collection.

But Firefox will return
amp;p1
amp;p2
amp;p3
And neither Browsers understand what is

i f (a &gt; b)

I have tried the memoryStream with output method= html and still got the
same results

Please let me know what to generate HTML contents contain
if (a b)

a.aspx?p1=v1&p2 =v2
as well-formed XML
Thanks

Michael

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:WS******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi,

The disable-output-escaping is in a gray area

From the XSLT 1.0 Spec http://www.w3.org/TR/xslt#disable-output-escaping:

"Since disabling output escaping may not work with all XSLT processors and
can result in XML that is not well-formed, it should be used only when
there
is no alternative."

So an XSLT processor is not required to support d-o-e.

In this case, you can try to use a StreamWriter to write out the results.

Please check the following links for more information about this issue.

http://msdn2.microsoft.com/en-us/lib...k9(VS.80).aspx
http://www.thescripts.com/forum/thread534528.html
http://forums.microsoft.com/MSDN/Sho...72483&SiteID=1

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 6 '06 #5
Oleg,
I verified my code again. I do have out method set to html and I am using memory Stream. The generated contents for the script block still showed a &gt; b instead of a b

I am not quite sure what I did wrong. Here are code fragments:

## from xsd
<?xml version="1.0" encoding="utf-8" ?>

<xsl:styleshe et version="1.0"

xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.microso ft.com/intellisense/ie5"

xmlns:msxsl="ur n:schemas-microsoft-com:xslt" >

<xsl:output method="html" encoding="utf-8" />

## from transform method

public static string Transform(Syste m.Xml.XPath.XPa thNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )

{

MemoryStream mry = new MemoryStream();

StreamReader sr = new StreamReader(mr y, System.Text.UTF 8Encoding.UTF8) ;

XslCompiledTran sform xt = PrepareCompiled Transform(xslPa th, resolver);

xt.Transform(na v, PrepareXsltArgu mentList(htArgu ments), mry);

mry.Position = 0;

string s = sr.ReadToEnd();

sr.Close();

return s;
}

Thanks

"Oleg Tkachenko [MVP]" <so**@body.comw rote in message news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
InvalidLastName wrote:
>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)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"an d output into Stream or TextWriter.

>// xsl contents
abc.aspx?p1=v1 &amp;p2=<xsl:va lue-of select="$v2" />
In HTML & in links must be escaped as &amp; Don't put efforts in
producing malformed HTML.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 6 '06 #6
InvalidLastName wrote:
I am not try to use d-o-e with XslCompiledTran sform. However, since the
behavior changed, I have to use d-o-e to make sure XslCompiledTran sform
generate HTML all the browsers can process. IE has no problem to read some
thing like

a.aspx?p1=v1&am p;p2=v1&amp;p3= v3

IE return
p1
p2
p3
in QueryString collection.

But Firefox will return
amp;p1
amp;p2
amp;p3
That is not true, Firefox will certainly handle a properly escaped
ampersand in a HTML document, see the link in
<http://www34.brinkster .com/libertydevelop/asp/test2006110601. html>
for an example.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 6 '06 #7
InvalidLastName wrote:
<xsl:styleshe et version="1.0"

xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.microso ft.com/intellisense/ie5"
Take that xmlns declaration out, html output method applies to elements
in no namespace while your default namespace declaration xmlns="..."
puts the element in a namespace and that way the html output method does
not apply to the elements your stylesheet generates.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 6 '06 #8
InvalidLastName wrote:
However, Firefox has trouble to recognize &amp; in the link as &. All
our parameters in the QueryString are returned as *amp;p1* instead of *p1*
Sorry, but I hardly believe Firefox doesn't support such basic HTML
specification requirement. I'm sure it does. You must be having double
escaping problem - chances are your output is &amp;amp;p1.

--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 6 '06 #9
InvalidLastName wrote:
<xsl:styleshe et version="1.0"

xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.microso ft.com/intellisense/ie5"
Yeah, Martin is right. This declaration drives XslCompiledTran sform
crazy. It actually makes your output elements to be not HTML, but custom
XML and so XslCompiledTran sform doesn't apply HTML output rules.

--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 6 '06 #10

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

Similar topics

0
1184
by: Jim Douglas | last post by:
Do they play well together? Anyone using the Sybase .NET provider. Any problems or should I stick with the Sybase OLEDB? Or worse check with the DataDirect folks for their .NET provider for Sybase? If you are using Sybase what are you using? We have issues with the Sybase 12.5 OleDBProvider and Sybase says is "not certified" for .NET. The...
1
1903
by: Daniel | last post by:
Does system.xml have any way to transofrm data with an xswl style sheet using strings like MSXML2 does? how to convert this to use System.XML so i do not depend on MSXML2 interop? static public string XslTransform(string style, string strdata) { MSXML2.IXMLDOMDocument pDoc = new MSXML2.DOMDocumentClass(); pDoc.async = false;...
2
1659
Fary4u
by: Fary4u | last post by:
Hi i'm trying to make 2 different Connection & Recordset in 1 single file But accessing main values from the Query String, this part is working fine but only problem to access the 2nd part of recordset or connection how to i do it? <html> <body> <% intProdID = Request.QueryString("intProdID") Dim pPath, ConString
8
5306
by: emailmygroup | last post by:
I am trying to decode character ‘#; but it is not working. Anybody knows how to decode this character?
5
2835
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
Hello all, I have an XmlException being thrown trying to use XslCompiledTransform while using the google api. My suspicion is there is some html decoding happening that I want to prevent... something like this being changed into this
2
3437
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 deprecated, and I should use XslCompiledTransform. For the most part changing to this object works fine, however I have noticed in some cases a...
0
2317
by: Mark Gold | last post by:
Hi! We have a VB application using Crystal Reports 6 that has worked successfully on hundreds of systems for over 10 years. Now, on one network, the application and access database does not close. It seems to hang on the command. When we open the application an peruse the screens without opening up a report (using crystal reports), the...
0
910
by: anasanjaria | last post by:
here is my xml code: filename: cdcollection.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- Edited by XMLSpy® --> <catalog> <cd> <title>Empire Burlesque</title>
0
7487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7934
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1033
muto222
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.