By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

<BR/> tag in XML content

P: n/a
I have an XML file that stores data from an HTML form. I use XSL to
display the data in HTML format. The data may have newline characters.
However, XSL is not displaying the newlines properly in the browser.
I even replaced all the newlines with <BR/> tags but eventhough I see
the tags in my source, I don't get a line break in the output document.
Any help would be greatly appreciated.

Sep 11 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
noor.rahman wrote:
I have an XML file that stores data from an HTML form. I use XSL to
display the data in HTML format. The data may have newline characters.
However, XSL is not displaying the newlines properly in the browser.
I even replaced all the newlines with <BR/> tags but eventhough I see
the tags in my source, I don't get a line break in the output document.
Any help would be greatly appreciated.


If you open the XML in a text editor, the raw text of the <br/> looks like
&lt;br/&gt; , right?

Remember that HTML payload in XML is just that - payload. XML will not see
the well-formed XML tag <br/>, and think "ahah, that's HTML, so copy it out
raw". It will see a valid XML tag, and won't emit it in the 'text' property
of the current node.

Also, depending on the actual XSL plumbing, you might need this attrocity:

&amp;lt;br/&amp;gt;

I'm not smart enough to understand if that's a bug or a feature...

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Sep 11 '05 #2

P: n/a
On Sun, 11 Sep 2005 19:45:05 GMT, "Phlip" <ph******@yahoo.com> wrote:
I'm not smart enough to understand if that's a bug or a feature...


I would go further to proclaim that you don't even understand the
question you commented on :)

--
Rex
Sep 11 '05 #3

P: n/a
thanks to both of you but i still have the problem :):) so what should
i do to fix it? is there anything/character i can put to insert a
line-break in xsl?

Sep 12 '05 #4

P: n/a
no*********@gmail.com wrote:
I have an XML file that stores data from an HTML form. I use XSL to
display the data in HTML format. The data may have newline characters.
However, XSL is not displaying the newlines properly in the browser.
I even replaced all the newlines with <BR/> tags but eventhough I see
the tags in my source, I don't get a line break in the output document.
Any help would be greatly appreciated.


&#xA; is certainly what you're looking for :

<xsl:template name="text" match="text()">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '&#xA;')">
<xsl:value-of select="substring-before($text, '&#xA;')"/>
<br/>
<xsl:call-template name="text">
<xsl:with-param name="text" select="substring-after($text,
'&#xA;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Sep 12 '05 #5

P: n/a


no*********@gmail.com wrote:
I have an XML file that stores data from an HTML form. I use XSL to
display the data in HTML format. The data may have newline characters.
However, XSL is not displaying the newlines properly in the browser.
XSL is not displaying anything in the browser, the browser displays the
HTML your XSL produced and thus if you have any HTML display issue you
need to look into how HTML displays white space like newline characters.

And HTML's normal rendering of white space is white space collapsing
meaning whether you author e.g. a paragraph as

<p>a
b
c
d
</p>

or

<p>a b c d</p>

the normal rendering will collpase several white space characters in the
source to one inter-word space so rendering might be alike

a b c d

So the solution is to understand how HTML works and if the whitespace in
an element is to matter then to use for instance the <pre> element e.g.

<pre>a
b
c
d
</pre>

I even replaced all the newlines with <BR/> tags but eventhough I see
the tags in my source, I don't get a line break in the output document.


We need to see a minimal XSLT stylesheet and minimal XML input to make
suggestions on what you might be doing wrong in terms of XSLT to have
<br> elements in HTML output generated with XSLT.

Or look first at Philippe's answer to find a template that transforms
text with line breaks into markup with <br/> elements.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 12 '05 #6

P: n/a
Thanks a lot guys!! Martin, your solutions with <PRE> tags worked like
a charm and did the trick.

Sep 12 '05 #7

P: n/a
no*********@gmail.com wrote:
thanks to both of you but i still have the problem :):) so what should
i do to fix it? is there anything/character i can put to insert a
line-break in xsl?


Output a real <br> element to HTML.

///Peter

Sep 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.