 |
| 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
|
|
|
|

March 17th, 2008, 11:01 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
line breaks
ok, ive googled line breaks in XSLT a ton and have tried every suggestion ive run across, all with no success. im trying to add a line break to my html output (not a <br />). any ideas?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<div id="bannerLinksContainer">
<ul id="bannerLinks">
<xsl:for-each select="MenuDataResult/Item/Item/Menu/Item">
<li>
<xsl:if test="position() = 1">
<xsl:attribute name="id">firstBannerLink</xsl:attribute>
</xsl:if>
<a href="{ItemLink}">
<xsl:value-of select="ItemTitle" />
</a>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
so far, ive tried:
Code:
<xsl:text>
</xsl:text>
#xA;
<xsl:text>#xA;</xsl:text>
#32;#xA;#xD;
any help is appreciated. happy st. patty's day!
CHEERS!
steve
|
|

March 17th, 2008, 11:10 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
I am not sure why you use xsl:output method="text" when your stylesheet creates HTML elements like div or ul or li elements.
You might want to try xsl:output method="html" instead, or if you want the output to be indented then you can try xsl:output method="html" indent="yes".
As for inserting line breaks, your attempts with xsl:text should work. However you need to be aware that browsers/user agents that render your HTML collapse white space including line breaks so you might not see any line breaks if the browser for instance renders
Code:
<p>Line 1
Line 2
Line 3
</p>
that will be rendered as
Code:
Line 1 Line 2 Line 3
|
|

March 17th, 2008, 11:11 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
First thing is to change
<xsl:output method="text" />
to
<xsl:output method="html" />
You can get a line break in your output using
<xsl:text>
</xsl:text>
But remember that it won't render as a line break in the browser.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 17th, 2008, 11:16 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
oops, sorry - i orginally had <xsl:output method="html" /> but i changed it to "text" over the course of trying get my line break.
hmmm, so what if i *need* the browser to recognize a line break? how would i go about that? (death to IE6!)
thanks,
steve
|
|

March 17th, 2008, 11:22 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
It is not an XSLT problem anymore, it is rather a HTML and/or CSS problem, use the 'pre' element and the proper CSS property e.g.
Code:
<pre style="white-space: pre;">Line 1
Line 2
Line 3
</pre>
will render three lines.
|
|

March 17th, 2008, 11:23 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
why not <br/>?
|
|

March 17th, 2008, 11:26 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
To generate a new line in the rendered output, write a <br/> element.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 17th, 2008, 11:31 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i apologize for the confusion, but the <br /> tag or CSS won't work to solve my problem. this is my current output which never wraps to the next line:
<div id="bannerLinksContainer"><ul id="bannerLinks"><li id="firstBannerLink"><a href="/#">Jobs</a></li>...</ul></div>
what i need to output is *exactly*:
<div id="bannerLinksContainer">
<ul id="bannerLinks">
<li id="firstBannerLink"><a href="/#">Jobs</a></li>
...
</ul>
</div>
i thought the <xsl:text> tag with a line break within it would've worked, but to no avail.
steve
|
|

March 17th, 2008, 11:38 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Which XSLT processor are you using?
|
|

March 17th, 2008, 11:45 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Does it help if you put xml:space="preseve" on your stylesheet e.g
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xml:space="preserve">
?
|
|
 |