Differences in XSL Transform between dotnet and MSXML

G

Guest

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:blush:utput 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
 
K

Kevin Yu [MSFT]

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."
 
G

Guest

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
 
K

Kevin Yu [MSFT]

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."
 
G

Guest

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
 
K

Kevin Yu [MSFT]

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."
 
G

Guest

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
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top