xsl strips xml newlines?

dajo

Senior member
Nov 7, 2000
635
0
0
Hello,

I have a very simple question which seems to have no simple answer. I want to keep the newlines in the source xml data (blanks between paragraphs) but I cannot find a way to retain those in the xsl output.

The only thing I've found which comes close is putting the xsl-valueof inside an xmp tag but that causes all other formatting such as font, wrapping from the container (a table cell) to be ignored.

Surely, there is a way to keep, or translate, newlines from the source xml data in the xsl output.

Anyone know how?
 

sunase

Senior member
Nov 28, 2002
551
0
0
Well if XMP is working like you say it is, than just changing it to a PRE tag instead will do what you want. PRE is a lot like XMP, but doesn't disable formatting.

I'm amazed your XSL transform isn't removing the line breaks, though. Line breaks are just another type of space in XML and HTML files. Any amount of space is allowed to be collapsed into a single one.

OF course there are ways to avoid this like PRE in HTML and xsl:preserve-space and whatnot in XSL.

edit: freaking ugly ass emoticons were enabled. I wish we could disable them for good.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: sunaseAny amount of space is allowed to be collapsed into a single one. Line breaks are just another type of space in XML and HTML files.
That's not true. For straight up DOM processing, text nodes are always preserved exactly as they are. When it starts to get iffy is when you have some sort of processor like an html renderer that has a different notion of whitespace.

Since an xsl execution is essentially building a new document from scratch, whitespace is often not taken seriously because otherwise you'd have to contort your xsl source to get the output formatted properly (whoops, I see your point, you were talking specifically about xsl :eek:).

Dajo, a few of the things you can try are the disable-output-escaping attribute that can appear on a few of the xsl elements, or xml entities like "& # 10 ;" (remove spaces and quotes...). I wish I could say that always helped though, I've personally had this problem and was able to solve it in XML Spy where I was writing the xsl but not in the final execution engine where the code was actually running :( I'm not sure if I tried preserve-space like sunase suggested.

Edit: fixing entity that the forum screwed up
 

dajo

Senior member
Nov 7, 2000
635
0
0
Thank you for your responses. Part of the problem is that I don't know what I am doing!

I've made some progress based on googling, which is to use xsl:copy-of rather than xsl:value-of. This successfully retains the embedded "br /" xml tags which generate the blanks between paragraphs. This achieves my immediate goal of preserving blank lines without losing the other formatting factors of font, etc.

Currently, I am doing a replace of the .Net vb vblf constant found in the table data with the "br /" tag which seems to work well.

Thanks again.


 

sunase

Senior member
Nov 28, 2002
551
0
0
Lol, I thought you meant actual new lines. Not the HTML BR line break elements.