471,071 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Differences in XSL Transform between dotnet and MSXML


I have noticed a difference in the processing of XSL transforms between
dotnet and MSXML. Dotnet formats the resulting output differently, and since
we use the <pre> tag in the HTML output it makes a big difference.

What is in fact correct here? I don't see that the XSL transform engine
should reformat the output in this way, and would like to know if this
difference is going to remain in future.

The transform in question can be split down into the following:

XML:
<?xml version="1.0" encoding="Windows-1252"?>
<?xml-stylesheet type="text/xsl" href="./test1.xsl"?>
<outer xml:space="preserve">
<inner> Text 1 </inner>
<inner> Text 2 </inner>
</outer>

XSL:
<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html"/>
<xsl:template match="outer">
<html>
<pre>
<xsl:apply-templates select="inner"/>
</pre>
</html>
</xsl:template>
<xsl:template match="inner">
<font color="#ff0000"><xsl:value-of select='.'/></font><nobr/>
</xsl:template>
</xsl:stylesheet>

The HTML resulting from this from MSXML is:

<html>
<pre>
<font color="#ff0000"> Text 1 </font><nobr></nobr><font color="#ff0000">
Text 2 </font><nobr></nobr></pre>
</html>

and from dotnet:

<html>
<pre>
<font color="#ff0000"> Text 1 </font>
<nobr>
</nobr>
<font color="#ff0000"> Text 2 </font>
<nobr>
</nobr>
</pre>
</html>

and obviously these look quite different in a browser.

Thanks for any suggestions,

Peter

Jul 21 '05 #1
7 1966
Hi Peter,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the result of XSLT from MSXML and .NET
XML makes much difference. If there is any misunderstanding, please feel
free to let me know.

Based on the result you have provided, these two HTML are actually the
same. .NET XML adds a return behind each element. If you open the result
HTML in Internet Explorer or other browsers, it will display the same thing.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2

Hallo Kevin,
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the result of XSLT from MSXML and .NET
XML makes much difference. If there is any misunderstanding, please feel
free to let me know.
Yes, that is exactly the problem.
Based on the result you have provided, these two HTML are actually the
same. .NET XML adds a return behind each element. If you open the result
HTML in Internet Explorer or other browsers, it will display the same thing.
No, they are very different. I assume you have not looked at the result of
transform in a browser. As you say, the dotnet result is formatting the
result, the MSXML result is not.

As we are using the <pre> in HTML statement this changes the look of the
output by adding a carriage return at the end of each line.

In the HTML samples I provided, the line beginning with the <font> tag is
produced on a single line, it only looks split due to the limited space here.
If you try copying these results into two HTML file and loading them you will
see what I mean.
. .NET XML adds a return behind each element


And to reiterate, this is then displayed by the <pre> tag, and that is
exactly my problem.

Peter

Jul 21 '05 #3
Hi Peter,

Thanks for pointing me out!

XSL Transformations (XSLT) uses the XML Document Object Model (DOM), not
the source document, to guide its transformation. Because the white space
has already been stripped to process the XML into the DOM, white space
characters are lost even before the transformation takes place. Most of the
XSLT-related methods for specifying white space in the source data document
or style sheets are applied too late to make a difference in formatting.

So could you please try to set preserveWhiteSpace property to true before
loading and saving to file? I think this might resolve the problem you're
facing.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4

Hallo Kevin,

Thanks for the suggestion. However, if you check the original XML, this is
already set:

<outer xml:space="preserve">

Just to be certainI also tried setting the "preserveWhiteSpace" flag in the
code and as expected it makes no difference.

I would rather need an option "disableOutputFormatting" on the transform
object since that is causing the trouble. Is anything like that available or
planned?

Thanks,

Peter

"Kevin Yu [MSFT]" wrote:
Hi Peter,

Thanks for pointing me out!

XSL Transformations (XSLT) uses the XML Document Object Model (DOM), not
the source document, to guide its transformation. Because the white space
has already been stripped to process the XML into the DOM, white space
characters are lost even before the transformation takes place. Most of the
XSLT-related methods for specifying white space in the source data document
or style sheets are applied too late to make a difference in formatting.

So could you please try to set preserveWhiteSpace property to true before
loading and saving to file? I think this might resolve the problem you're
facing.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5
Hi Peter,

I think this is the default behavior of MSXML. I'm not quite sure if there
will be any changes to this. But I will try to forward your feedback to the
product team. Thank you!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #6

Hello Kevin,

Just to clear up any confusion.
I think this is the default behavior of MSXML.
1) Yes, I know that is the default behaviour of MSXML.
2) That is GOOD. I have no problems with MSXML
3) It is NOT the default behaviour of dotnet.
4) I have a problem with dotnet.

If you are able to forward the request to anyone, please ask the dotnet team
to make the transform work the same way as MSXML, or at least offer an option
to enable this compatibility.

In the meantime we will unfortunately remove have to remove our dotnet
support and recommend our customers do the same.

Thanks and best regards,

Peter
"Kevin Yu [MSFT]" wrote:
Hi Peter,

I think this is the default behavior of MSXML. I'm not quite sure if there
will be any changes to this. But I will try to forward your feedback to the
product team. Thank you!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #7
Thanks, Peter. I will do that. Thanks again for your feedback.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by tcdevelopment | last post: by
1 post views Thread by Danny Lesnik | last post: by
reply views Thread by leo001 | last post: by

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.