?
Solved

HOWTO replace newline to <BR> with XSL

Posted on 2002-04-16
6
Medium Priority
?
7,736 Views
Last Modified: 2012-05-04
Hello guys!

HOWTO replace newline to <BR> with XSL.

I get my text from VB form, store in database.
Later I'd like to show the stored text with Browser.
I get te text with ADO, build a XML text, and joint with XSL but,
the newline character don't "newline".

Then: HOWTO replace newline to <BR> with XSL?

Thanks a lot.
0
Comment
Question by:jussara
6 Comments
 
LVL 3

Expert Comment

by:ivanc
ID: 6947012
jussara
You may want to try the replace with <BR /> instead

Hope this helps
Ivanc
0
 
LVL 1

Expert Comment

by:RobinPatra
ID: 6947137
In the XML text that u r building in the run time has got <br> associated with it for new line.

If yes then in the <xsl:value> tag use a attribute called as "disable-output-escaping" and set its value set to "yes"
0
 

Author Comment

by:jussara
ID: 6947438
The text from VB form have only normal ASCII text. No extra tags for any meta-language.

For example:
body of text body of text body of text
body of text body of text body of text
-here is an item
-here is another item
More body of text body of text body of text

You see newlines here to wrap lines (of course).
Well, I need to show this text on Web pages and other forms. I want to let the original text original.
There is no problem to show this text on VB form.
To show this text in Browser with HTML produced through XML and XSL I don't know and waiting for a response.
The value field is exactly like original text but inside a CDATA and must be in this form.
Then, HOWTO replace newline to <BR> with XSL?

thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Expert Comment

by:b1xml2
ID: 6947469
jussara,

if you want a real solution, pls conform to EE Guidelines, and experts with the right skillset can help you.

50 points - simple question
100 points - average question
200 points - difficult question
300 points+ - very difficult.

Thus far, what has been proposed is out of the point completely.
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 6947655
XML Document
============
<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<item description="I am here
and so are you and this sentence


is found inside an attribute" />
<item>This sentence is found as part
of a text node inside an element

cheers
</item>
</data>

XSLT Document
=============
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="iso-8859-1" />
<xsl:variable name="linefeed"><xsl:text>&#x0a;</xsl:text></xsl:variable>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="//item" />
</body>
</html>
</xsl:template>

<!--template that uses attributes-->
<xsl:template match="item[@description]">
<div id="attribute">
<xsl:call-template name="recursion">
<xsl:with-param name="raw"><xsl:value-of select="@description" disable-output-escaping="yes" /></xsl:with-param>
</xsl:call-template>
<xsl:if test="@description[contains(.,$linefeed)]">yes</xsl:if>
</div>
</xsl:template>


<!--template that uses text nodes-->
<xsl:template match="item[not(@description)]">
<div id="element">
<xsl:call-template name="recursion">
<xsl:with-param name="raw" select="." />
</xsl:call-template>
</div>
</xsl:template>

<!--template that handles the recursion-->
<xsl:template name="recursion">
<xsl:param name="raw" />
<xsl:choose>
<xsl:when test="contains($raw,$linefeed)">
<xsl:value-of select="substring-before($raw,$linefeed)" /><br />
<xsl:call-template name="recursion">
<xsl:with-param name="raw" select="substring-after($raw,$linefeed)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="string-length($raw) != 0">
<xsl:value-of select="$raw" />
</xsl:when>
<xsl:otherwise />
</xsl:choose>
</xsl:template>

</xsl:stylesheet>


HTML Output
===========
<html>
<body>
<div id="attribute">I am here and so are you and this sentence   is found inside an attribute</div>
<div id="element">This sentence is found as part<br>of a text node inside an element<br><br>cheers<br></div>
</body>
</html>


Notes
=====
1. Attribute values are normalized and thus cannot use the recursion technique.
2. Text nodes can use the recursion technique
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6947667
the template,
<xsl:template match="item[@description]" is just a test to demo the effects on attributes,

thus, the proper additions to your XSLT are as follows:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="iso-8859-1" />
<xsl:variable name="linefeed"><xsl:text>&#x0a;</xsl:text></xsl:variable>

<!--template that handles the recursion-->
<xsl:template name="recursion">
<xsl:param name="raw" />
<xsl:choose>
<xsl:when test="contains($raw,$linefeed)">
<xsl:value-of select="substring-before($raw,$linefeed)" /><br />
<xsl:call-template name="recursion">
<xsl:with-param name="raw" select="substring-after($raw,$linefeed)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="string-length($raw) != 0">
<xsl:value-of select="$raw" />
</xsl:when>
<xsl:otherwise />
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

you call the named template like so,
<xsl:call-template name="recursion">
<xsl:with-param name="raw" select="." />
</xsl:call-template>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question