Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2010, 12:04 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default Extra white spaces in parsed XML?

I'm not sure why, but for what ever reason each XML that I parse has an extra blank white space at the end of each node.

Example:

Standard XML
Code:
<xml>
        <testing name="Bob" last_name="Johnson"/>
        <id number="00001"/>
         ...
</xml>
Parsed XML
Code:
<xml>
        <testing name="Bob" last_name="Johnson" />
        <id number="00001" />
         ...
</xml>
-- XSL
Code:
<!DOCTYPE xsl:stylesheet [
    <!ENTITY newline "<xsl:text>&#xA;</xsl:text>">
    <!ENTITY nbsp "<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>">
    <!ENTITY lt "<xsl:text disable-output-escaping='yes'>&amp;lt;</xsl:text>">
]>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
  <xsl:template>
     <xsl:copy-of select="."/>
  </template>  
</xsl:stylesheet>

Additional Details:
XSL Engine: NXSLT
XSLT version: 1.0
 
Old May 4th, 2010, 12:08 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

And....?

The "whitespace" you are referring to is irrelevant, so why do you have a problem with it being there?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 4th, 2010, 12:10 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't know what NXSLT is but probably the serializer it uses has been written to serialize empty elements the way you describe. There is nothing wrong with that in terms of XML, on the other hand it is not necessary to do that with "normal" XML, only XHTML to be served as text/html would need that serialization.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old May 4th, 2010, 12:12 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

While I realize that the whitespace is "irrelevant" to some people, I would prefer consistency between my documents. Additionally, this is something that I'd like to get to the bottom of just for the sake of understanding why it happens.
 
Old May 4th, 2010, 12:20 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

NXSLT is a command line utility that allows to perform XSL Transformations (XSLT) using .NET Framework's. NXSLT basically duplicates functionality and command line options, provided by Microsoft's MSXSL.EXE Command Line Transformation Utility.

Anyways...so you think this has to do with the XSL engine (NXSLT) or could it be something else? Is there any work around for this?

Quote:
Originally Posted by Martin Honnen View Post
I don't know what NXSLT is but probably the serializer it uses has been written to serialize empty elements the way you describe. There is nothing wrong with that in terms of XML, on the other hand it is not necessary to do that with "normal" XML, only XHTML to be served as text/html would need that serialization.
 
Old May 4th, 2010, 12:31 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I doubt the XSLT processor or engine is some implementation other than Microsoft's .NET XslCompiledTransform (or maybe .NET's XslTransform if that is some old .NET 1.x code). And serialization in the .NET framework usually happens with some implementation of System.Xml.XmlWriter. Try some .NET code writing out an empty XML element with an XmlWriter implementation in the .NET framework and it probably produces that output. So you would need to override the relevant XmlWriter methods (WriteEndElement) with some wrapper or extension of an existing XmlWriter implementation to ensure you get the format you want and then make sure your XSLT transformation uses your custom XmlWriter. Whether that is possible with your command line tool I don't know, check whether it has an option to provide your own XmlWriter for serialization.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
A parsed text file to an Access table? josmith2 ADO.NET 0 May 10th, 2007 01:52 PM
A parsed text file to an Access table? josmith2 VB Databases Basics 0 May 8th, 2007 07:13 AM
Extra Spaces Added When Inserting rsearing ASP.NET 2.0 Basics 3 January 8th, 2007 10:56 AM
UNDERSCORE when parsed jmaronilla PHP Databases 1 September 16th, 2004 11:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.