<BR/> tag in XML content

N

noor.rahman

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

Phlip

noor.rahman said:
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...
 
J

Jan Roland Eriksson

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 :)
 
N

noor.rahman

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

Philippe Poulard

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.


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, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br/>
<xsl:call-template name="text">
<xsl:with-param name="text" select="substring-after($text,
'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$text"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
M

Martin Honnen

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

noor.rahman

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

Peter Flynn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top