Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old August 11th, 2008, 05:27 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default extra space???

Hi guys..

Does anyone know why the following code adds an extra space..

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template name="pound">
        <xsl:text disable-output-escaping="yes">&amp;</xsl:text>pound;
    </xsl:template>
    <xsl:template match="/root">
    <p><xsl:call-template name="pound" /><xsl:value-of select="/root/dataItem[name='test']/price" /></p>
    </xsl:template>
</xsl:stylesheet>
this is the outcome.. £ 100

here is the simple XML...

Code:
<root>
  <dataItem>
    <name>test</name>
    <price>100</price>
  </dataItem>
</root>
Cheers

Darren



  #2 (permalink)  
Old August 11th, 2008, 05:35 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

XSLT treats whitespace as significant when it appears in a text node which contains none-whitespace characters.

So basically the character return after the "pound;" is considered significant. You can fix this by simply moving the end tag for the xsl:template to straight after the text:

<xsl:template name="pound">
    <xsl:text disable-output-escaping="yes">&amp;</xsl:text>pound;</xsl:template>


/- Sam Judson : Wrox Technical Editor -/
  #3 (permalink)  
Old August 11th, 2008, 05:55 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default

excellent (and simple) fix..

cheers

Daz



Similar Threads
Thread Thread Starter Forum Replies Last Post
nested <div> creates extra space sstuber BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 May 2nd, 2008 09:56 AM
CMS extra features outofwork BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 August 26th, 2006 03:29 AM
Stripping out extra space around an italic word simone_s XSLT 2 April 25th, 2006 03:50 AM
How to eliminate all the extra zero? kuku SQL Server 2000 3 June 29th, 2005 09:47 PM
Extra Processor ryant SQL Server 2000 2 October 9th, 2003 08:55 AM





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