473,408 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XslTransform Problems with Whitespace

I'm using XslTransform to apply a transform to an XML document, however I
get validation problems when parsing the resulting XML document due to
invalid whitespace. I'm passing in an XPathNavigator for the input to the
Transform method and specifying a Stream for the output.

Here is an example of a transform and a document (it's the IconStyle
sections that are causing problems):

<?xml version="1.0" encoding="UTF-16"?>
<!-- Copyright i2 Ltd 2002-2003. All rights reserved. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-16"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Calls">
<Doc>
<ItemCollection>
<xsl:for-each select="Call">
<xsl:element name="Item">
<xsl:attribute name="Label"><xsl:value-of
select="@from"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle">
<xsl:attribute name="Type">Telephone</xsl:attribute>
</xsl:element>
</Icon>
</xsl:element>
<xsl:element name="Item">
<xsl:attribute name="Label"><xsl:value-of
select="@to"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle">
<xsl:attribute name="Type">Telephone</xsl:attribute>
</xsl:element>
</Icon>
</xsl:element>
</xsl:for-each>
</ItemCollection>
</Doc>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-16"?>
<Calls>
<Call from="01339 842744" to="01226 441998" duration="2"/>
<Call from="01339 842744" to="01226 441998" duration="3"/>
<Call from="01663 254564" to="01882 123456" duration="3"/>
<Call from="01226 441998" to="01339 842744" duration="12"/>
<Call from="01882 123456" to="01663 868943" duration="7"/>
</Calls>

I was previously using MSXML4, which would produce something as follows:

<IconStyle Type="Telephone"/>

Now I understand that the above is considered to be identical to the
following:

<IconStyle Type="Telephone"></IconStyle>

Unfortunately when running the same transform on the same document using
XslTransform, the result is as follows:

<IconStyle Type="Telephone">
</IconStyle>

AFAICT this is not equivalent to the MSXML4 result. If I turn off indenting
in the transform then the transformed XML is valid but has no formatting
whatsoever. Am I missing something about using XslTransform or was the
previous behaviour of MSXML4 wrong?

--
Kevin Westhead
Nov 12 '05 #1
5 1815
Kevin Westhead wrote:
I'm using XslTransform to apply a transform to an XML document, however I
get validation problems when parsing the resulting XML document due to
invalid whitespace. I'm passing in an XPathNavigator for the input to the
Transform method and specifying a Stream for the output.

Here is an example of a transform and a document (it's the IconStyle
sections that are causing problems):

<?xml version="1.0" encoding="UTF-16"?>
<!-- Copyright i2 Ltd 2002-2003. All rights reserved. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-16"/>


Turn output indentation off if you care about whitespace in the result
document:
<xsl:output method="xml" indent="no" encoding="UTF-16"/>

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...

<snip>
Turn output indentation off if you care about whitespace in the result
document:
<xsl:output method="xml" indent="no" encoding="UTF-16"/>

Thanks for the response. This is pretty much the behaviour I have observed,
as mentioned at the end of my posting. Can you shed any more light on why
this is the case, e.g. is it expected behaviour based on the W3C specs or is
it just a limitation in XslTransform? Are there any other workarounds that
you know of, e.g. would using a different Transform overload make any
difference?

--
Kevin Westhead
Nov 12 '05 #3
Hi Kevin,

This is a "by design" feature of XSLElment in .NET System.XML.XSL. And this
is different from MSXML 4.0.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 12 '05 #4
"MSFT" <lu******@online.microsoft.com> wrote in message
news:k$**************@cpmsftngxa07.phx.gbl...
This is a "by design" feature of XSLElment in .NET System.XML.XSL. And this is different from MSXML 4.0.


Thank you for responding.

Are there any workarounds? Is it possible for me to disable indenting even
if the loaded stylesheet has indent="yes" specified? I have no control over
the stylesheets, I simply need to apply them to a specified document in
code. I think it would be an extreme measure to say that all stylesheets
cannot specify indenting. Surely this is a bug since the resulting XML is
wrong, i.e. the element contains whitespace when it should be empty? Are you
saying that the following is an acceptable output for the section of the
transform I posted that creates an IconStyle element?

<IconStyle Type="Telephone">
</IconStyle>

If so, is there anyway I can force the output to be either of the following?

<IconStyle Type="Telephone"></IconStyle>

or

<IconStyle Type="Telephone"/>
--
Kevin Westhead
Nov 12 '05 #5
Kevin Westhead wrote:
Are there any workarounds? Is it possible for me to disable indenting even
if the loaded stylesheet has indent="yes" specified? I have no control over
the stylesheets, I simply need to apply them to a specified document in
code.
Sure you can. Just transform to XmlWriter. Then indentation specified in
the stylesheet is ignored and you can disable indentation on that
XmlWriter using Formatting property.
Are you
saying that the following is an acceptable output for the section of the
transform I posted that creates an IconStyle element?

<IconStyle Type="Telephone">
</IconStyle>

Btw, have you tried to ignore such insignificant whitespace while
validating document? Take a look at WhitespaceHandling property of
XmlTextReader class.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Nov 12 '05 #6

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

Similar topics

2
by: Anthony Bouch | last post by:
Can anyone tell me why I receive the following compiler warning after having recently upgraded to VS.Net 2003 and .Net 1.1? Warning CS0618: 'System.Xml.Xsl(System.Xml.XPath.IXPathNavigable,...
1
by: Rodger McNab | last post by:
While parsing xpath expressions within an XSLT document the .NET XslTransform class seems to delete the first "/" after a "]" within an expression containing a "|". This problem can be demonstrated...
1
by: Ronald | last post by:
I just wrote some code on a dev machine, Imports System.Xml Imports System.Xml.XPath Imports System.Xml.Xsl Imports System.IO Imports System.Data.SqlClient Public Class ClassXMLtoHTML Dim...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
2
by: KJS | last post by:
Hello, I'm receiving: 'System.Xml.Xsl.XsltException: Missing mandatory attribute 'version' After I try and run my transformation. I spent a good few days coming up with the appropriate (I think)...
1
by: manlio | last post by:
how can I load a XSL string (not an xsl file!!) with XslTransform ??? If I use the code: // Create a new XslTransform class and load the stylesheet XslTransform myXslTransform = new...
3
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...
2
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...
0
by: bryhi | last post by:
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. #pragma warning disable // because we are using a depricated...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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
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
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
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...

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.