LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-11-2006, 12:02 AM   #1
Stabby McTwist
Member
 
Registered: May 2006
Distribution: Mandrake, Ubuntu, Kubuntu, SuSE
Posts: 63

Rep: Reputation: 15
XML not doing linebreaks?


How can I get an XML+XSL page to do linebreaks? I've tried replacing \n with <br /> (via php) and it still doesn't do anything. The XML file itself shows the linebreaks, but displayed in the browser it does not.
 
Old 12-11-2006, 05:02 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
don't get it, which browser? The browser will render as it sees fit
irrespective of linebreaks or no in the XML.

do you mean in your raw XML? How to do it in XSL?

If you just want indenting put this in your XSL stylesheet:
Code:
   <xsl:output indent="yes" method="xml"/>
or a new line:
Code:
<!-- new line -->
<xsl:text>
</xsl:text>

Last edited by bigearsbilly; 12-11-2006 at 05:06 AM.
 
Old 12-11-2006, 11:21 AM   #3
Stabby McTwist
Member
 
Registered: May 2006
Distribution: Mandrake, Ubuntu, Kubuntu, SuSE
Posts: 63

Original Poster
Rep: Reputation: 15
The raw XML data shows up just fine with linebreaks, but when the stylesheet is put on it, they all disappear and it becomes one big block of text. Even if I put <br />'s in where I need new lines. I'm using Firefox 2.0.

OH! The browser is reading <br /> as an XML tag and ignoring it as far as HTML goes. Is there a way around this?

Last edited by Stabby McTwist; 12-11-2006 at 11:33 AM.
 
Old 12-12-2006, 03:15 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
did you try my suggestions?
 
Old 12-12-2006, 05:48 PM   #5
Stabby McTwist
Member
 
Registered: May 2006
Distribution: Mandrake, Ubuntu, Kubuntu, SuSE
Posts: 63

Original Poster
Rep: Reputation: 15
Using the xslutput indent does nothing. The xsl:text thing gives me a parser error and apparently is designed to be used on hard-coded text as opposed to xml data.

Last edited by Stabby McTwist; 12-12-2006 at 06:08 PM.
 
Old 12-13-2006, 02:20 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
they both work for me in sylesheets.

maybe your XSLT engine is rubbish.
I use saxon.
an example would help
 
Old 12-15-2006, 09:14 AM   #7
Stabby McTwist
Member
 
Registered: May 2006
Distribution: Mandrake, Ubuntu, Kubuntu, SuSE
Posts: 63

Original Poster
Rep: Reputation: 15
I'm really not sure what XSLT engine I have.

Code:
<root>
<text>
blah blah

blah blah
</text>
</root>
Code:
<xsl:value-of select="text" />
That yields "blah blahblah blah".
 
Old 12-15-2006, 09:27 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
CUT
see next reply

Last edited by bigearsbilly; 12-15-2006 at 09:35 AM.
 
Old 12-15-2006, 09:41 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Hmm works for me ?


Code:
 

billy-$ cat 1.xml 
<root>
<text>
blah blah

blah blah
</text>
</root>

Code:
billy-$ cat 1.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:fo="http://www.w3.org/1999/XSL/Format">


<xsl:output method="text"/>


<xsl:template match="/root">

    <xsl:value-of select="text" />

</xsl:template>


</xsl:stylesheet>
Code:
billy-$ xt 1.xml 1.xsl
blah blah

blah blah
billy-$
(FYI xt is an alias for a long java saxon command
xt='java -Xmx512M -jar /export/home/billym/app/saxon/saxon7.jar')
 
Old 12-15-2006, 09:49 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
if you are talking about how it looks in a browser, then that's down to the browser.
 
Old 01-13-2007, 11:16 AM   #11
ronald-be
Member
 
Registered: Aug 2004
Location: Belgium
Distribution: debian 5.02
Posts: 73

Rep: Reputation: 15
Lightbulb linebreaks in XML

hello,

The xsl:text is indeed intended for hard-coded text. A blank <xsl:text></xsl:text> could solve the problem but is considered as not a good practice : you could get problems with handling of orphans and widows and, generally, the whole page-layout. The best thing remains to put it in a separate paragraph. Try to structure your document as detailed as possible.

Greetings,

Ronald
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
How to use XML AMMullan Programming 7 12-15-2006 09:31 AM
LXer: StAX’ing up XML: Streaming API for XML LXer Syndicated Linux News 0 11-30-2006 07:54 AM
configure: error: could not find DocBook XML DTD V4.1.2 in XML catalog Fadoksi Linux - Software 1 07-16-2006 06:41 AM
xml bong.mau Programming 1 11-22-2005 02:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration