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&p2=<xsl:value-of select="$v2" />
However, since we switched to replace XslTransform with XslCompiledTransform, 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 XslCompiledTransform without be wrapped within xsl:text without doe
if (a > b)
....
abc.aspx?p1=v1&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 XslCompiledTransform handle those entity classes, e.g. &, >, < , as XslTransform
// using StringWriter version
public static string Transform(System.Xml.XPath.XPathNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XslCompiledTransform xt = PrepareCompiledTransform(xslPath, resolver);
xt.Transform(nav, PrepareXsltArgumentList(htArguments), sw);
sw.Close();
xt = null;
return sb.ToString();
}
// using xml writer
public static string Transform(System.Xml.XPath.XPathNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XslCompiledTransform xt = PrepareCompiledTransform(xslPath, resolver);
XmlWriterSettings settings = xt.OutputSettings.Clone();
settings.CheckCharacters = false;
settings.CloseOutput = true;
XmlWriter xw = XmlWriter.Create(sb, settings);
xt.Transform(nav, PrepareXsltArgumentList(htArguments), xw);
xw.Close();
sw.Close();
return sb.ToString();
}
// using memory stream
public static string Transform(System.Xml.XPath.XPathNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
// use memroystream
MemoryStream mry = new MemoryStream();
StreamReader sr = new StreamReader(mry, System.Text.UTF8Encoding.UTF8);
XslCompiledTransform xt = PrepareCompiledTransform(xslPath, resolver);
xt.Transform(nav, PrepareXsltArgumentList(htArguments), mry);
mry.Position = 0;
string s = sr.ReadToEnd();
sr.Close();
return s;
}
private static XslCompiledTransform PrepareCompiledTransform(string xslPath, XmlResolver stylesheetResolver )
{
bool bEnableDebug = false;
XslCompiledTransform xt = new XslCompiledTransform(bEnableDebug);
XsltSettings settings = new XsltSettings();
settings.EnableDocumentFunction = true;
XmlResolver theResolver = (stylesheetResolver == null ? new XmlUrlResolver() : stylesheetResolver);
xt.Load(GetXmlFilePath(xslPath), settings, theResolver);
return xt;
} 12 9846
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.)
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 > b)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"and output into Stream or TextWriter.
// xsl contents
abc.aspx?p1=v1&p2=<xsl:value-of select="$v2" />
In HTML & in links must be escaped as & 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
Thank for the reply.
However, Firefox has trouble to recognize & in the link as &. All our parameters in the QueryString are returned as amp;p1 instead of p1
"Oleg Tkachenko [MVP]" <so**@body.comwrote in message news:%2****************@TK2MSFTNGP04.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 > b)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"and output into Stream or TextWriter.
>// xsl contents abc.aspx?p1=v1&p2=<xsl:value-of select="$v2" />
In HTML & in links must be escaped as & 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
Hi Kevin,
I am not try to use d-o-e with XslCompiledTransform. However, since the
behavior changed, I have to use d-o-e to make sure XslCompiledTransform
generate HTML all the browsers can process. IE has no problem to read some
thing like
a.aspx?p1=v1&p2=v1&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 > 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.microsoft.comwrote in message
news:WS**************@TK2MSFTNGXA01.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.)
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 > 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:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.microsoft.com/intellisense/ie5"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
<xsl:output method="html" encoding="utf-8" />
## from transform method
public static string Transform(System.Xml.XPath.XPathNavigator nav, string xslPath, Hashtable htArguments, XmlResolver resolver )
{
MemoryStream mry = new MemoryStream();
StreamReader sr = new StreamReader(mry, System.Text.UTF8Encoding.UTF8);
XslCompiledTransform xt = PrepareCompiledTransform(xslPath, resolver);
xt.Transform(nav, PrepareXsltArgumentList(htArguments), mry);
mry.Position = 0;
string s = sr.ReadToEnd();
sr.Close();
return s;
}
Thanks
"Oleg Tkachenko [MVP]" <so**@body.comwrote in message news:%2****************@TK2MSFTNGP04.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 > b)
Script should go out with no escaping. Just make sure you output HTML -
set <xsl:output method="html"and output into Stream or TextWriter.
>// xsl contents abc.aspx?p1=v1&p2=<xsl:value-of select="$v2" />
In HTML & in links must be escaped as & 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
InvalidLastName wrote:
I am not try to use d-o-e with XslCompiledTransform. However, since the
behavior changed, I have to use d-o-e to make sure XslCompiledTransform
generate HTML all the browsers can process. IE has no problem to read some
thing like
a.aspx?p1=v1&p2=v1&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/
InvalidLastName wrote:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.microsoft.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/
InvalidLastName wrote:
However, Firefox has trouble to recognize & 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;p1.
--
Oleg Tkachenko [XML MVP, MCPD] http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
InvalidLastName wrote:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.microsoft.com/intellisense/ie5"
Yeah, Martin is right. This declaration drives XslCompiledTransform
crazy. It actually makes your output elements to be not HTML, but custom
XML and so XslCompiledTransform doesn't apply HTML output rules.
--
Oleg Tkachenko [XML MVP, MCPD] http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Hi Martin,
Thanks for pointing this out. Yes, you are correct. The Firefox works when the & embedded the <A href>
I did more researches on why I got the Firefox issue at first place, and it turned that our page was opened by Javascript as
var s = "test.aspx?p1=v1&p2=v2&p3=v3";
document.location = s; //
Please see following full example:
<html>
<head>
</head>
<body>
<a href="test.aspx?p1=v1&p2=v2&p3=v3">this will work in IE and Firefox<a>
<script>
function openWin()
{
var s = "test.aspx?p1=v1&p2=v2&p3=v3";
document.location = s;
//window.open(s, "popup", "height=500, width=700, menubar, scrollbars, resizable, status");
}
</script>
<br/>
<a href="javascript :openWin()">this will not work in Firefox</a>
</body>
</html>
In Firefox:
result from first link: http://localhost/test.aspx?p1=v1&p2=v2&p3=v3
result from second link: http://localhost/test.aspx?p1=v1&p2=v2&p3=v3
Any suggestion is really appreciated. Thanks
- ILN
"Martin Honnen" <ma*******@yahoo.dewrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
InvalidLastName wrote:
>I am not try to use d-o-e with XslCompiledTransform. However, since the behavior changed, I have to use d-o-e to make sure XslCompiledTransform generate HTML all the browsers can process. IE has no problem to read some thing like
a.aspx?p1=v1&p2=v1&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/
Oleg and Martin,
Thank both of you. This is not the first time I got helps from you two =).
After I taking out the xml declaration xmlns="http://schemas.microsoft.com/intellisense/ie5", everything start working just like old XslTransform
The reason we had that declaration is for intellisense on HTML elements in .NET 1.1. That does mess up the element namespace =(
Really appreciate it
ILN
"Oleg Tkachenko [MVP]" <so**@body.comwrote in message news:45**************@body.com...
InvalidLastName wrote:
><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.microsoft.com/intellisense/ie5"
Yeah, Martin is right. This declaration drives XslCompiledTransform
crazy. It actually makes your output elements to be not HTML, but custom
XML and so XslCompiledTransform doesn't apply HTML output rules.
--
Oleg Tkachenko [XML MVP, MCPD] http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Hi ILN,
I'm sorry, but I don't have FireFox for testing.
It seems that you have resolved the problem by removing
xmlns="http://schemas.microsoft.com/intellisense/ie5". If you have any
other question, please feel free to post them in the community.
Kevin Yu
Microsoft Online Community Support
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
by: emailmygroup |
last post by:
I am trying to decode character #; but it is not working. Anybody
knows how to decode this character?
|
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...
|
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...
|
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,...
|
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>...
|
by: tammygombez |
last post by:
Hey fellow JavaFX developers,
I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |