473,732 Members | 2,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et 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:attribut e name="Label"><x sl:value-of
select="@from"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle ">
<xsl:attribut e name="Type">Tel ephone</xsl:attribute>
</xsl:element>
</Icon>
</xsl:element>
<xsl:element name="Item">
<xsl:attribut e name="Label"><x sl:value-of
select="@to"/></xsl:attribute>
<Icon>
<xsl:element name="IconStyle ">
<xsl:attribut e name="Type">Tel ephone</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 1840
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:styleshe et 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!P LEASEtkachenko. com> wrote in message
news:Oc******** ******@TK2MSFTN GP10.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******@onlin e.microsoft.com > wrote in message
news:k$******** ******@cpmsftng xa07.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 WhitespaceHandl ing 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
5820
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, System.Xml.Xsl.XsltArgumentList, System.Xml.XmlWriter)' is obsolete: 'You should pass XmlResolver to Transform() method' XPathDocument xmlData = new XPathDocument(memStream); XslTransform xslTransform = new XslTransform();...
1
1892
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 by the following short C# program. The program throws an exception saying that "ac" is an invalid XPath expression. using System; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl;
1
2110
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 myXslTransform As XslTransform Sub New(ByVal strXSL As String)
3
2269
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 use this so that we can specify different templates to be used by the same xml node. Know that we could use global params, but would rather not have to update all teh stylesheets and any code that uses msxml and the same stylesheets.
2
3719
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) methods, and overrides for this task. I have verified that the source XML and XSL will transform by means of using the MSXML command line parsing tool (previous version of MSXML though). Here is my code:
1
2792
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 XslTransform(); myXslTransform.Load("myFile.xsl"); it run, but I need load an XSL string:
3
4227
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 untouched when I use XslTransform to do the transformation. But after switching to XslCompiledTransform the tabs are transformed to a single space in the result file, which leads to problems later on the the program. what I found was:...
2
3457
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 difference of behavior that breaks the proper running of my app. I am using XSL templates to transform...
0
1240
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 object static void Main(string args) { /* * There are two problems: * 1. The characters (CRLF) are not being output by the new object. * 2. Anything not in xml tags causes a crlf to be inserted. */
0
8946
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.