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 August 19th, 2010, 08:13 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default Line Break Problem

Hi All,

I want to add line break in the xslt but it not working.

Below is the code for adding the line break.

[code]

<xsl:variable name="Collection7">
<xsl:value-of select="$13932"/><xsl:text>&#xa;</xsl:text>
<xsl:value-of select="$31042"/><xsl:text>&#xa;</xsl:text>
</xsl:variable>

<td><xsl:value-of select="$Collection7"/></td>

</code]

I have tried the below code as well:

<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
or
<xsl:variable name="break">&lt;br&gt;</xsl:variable>
or

addign <br/>

then also it not adding the line break.

But If I write code like below then it is adding the line break and it works fine.

[code]

<td><xsl:value-of select="$13932"/><br/>
<xsl:value-of select="$31042"/>
</td>
</code]

But the above code I cannot use because there is some requirement, so for that I have to make collection of the values in the variable and then I have to use the Variable's value in the <TD>.

Any Help much appriciated.

Thanks
Nelly

Last edited by nelly78; August 19th, 2010 at 08:37 AM..
 
Old August 19th, 2010, 08:17 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Code:
<xsl:variable name="Collection7">
  <xsl:value-of select="$Attr_4091_13932"/><br/>
  <xsl:value-of select="$Attr_7283_31042"/><br/>
</xsl:variable>
 
<td><xsl:copy-of select="$Collection7"/></td>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
nelly78 (August 19th, 2010)
 
Old August 19th, 2010, 08:45 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thank you very much Martin, Its works.
 
Old August 19th, 2010, 09:41 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The reason for this is that <xsl:value-of> returns the textual content of a element or set of elements. <br/> is an empty br element with no text in it.

On the other hand <xsl:copy-of> copies the entire tree of the selected node or node-set, including the elements and text.

Code:
<xsl:variable name="test">
  <element>test</element>
</xsl:variable>

<xsl:value-of select="$test"/> <!-- outputs "test" only -->
<xsl:copy-of select="$test"/> <!-- outputs "<element>test</element>" -->
Your first two example should have successfully outputted a line break, but if viewed in a browser this line break has no effect on the actual display of the text, as you have probably seen.

Code:
<p>This line has a 
   break in it.</p>
<p>This line has a <br/> line break element in it.</p>
when viewed in a browser will simply view as

Code:
This line has a break in it.
This line has a 
line break element in it.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 19th, 2010, 09:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The other part of the explanation, of course, is that HTML does not render a newline as a newline: all runs of whitespace in HTML are rendered as a single space. So putting a newline character in the HTML achieves nothing.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
result line break. cowbell1 Java Basics 1 October 18th, 2007 05:28 AM
line break Cyber Shiva HTML Code Clinic 1 May 17th, 2007 06:04 AM
VC++: line break problem in edit box bluebeta Visual C++ 1 May 12th, 2006 08:28 PM
line break problem XSLT 1 February 20th, 2006 11:18 AM
break up line crmpicco Javascript How-To 1 June 6th, 2005 06:54 AM





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