Solved

HOWTO replace newline to <BR> with XSL

Posted on 2002-04-16
6
7,709 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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 50 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting lots of W3C errors in my XHTML site... 43 73
XML to SQL Table using c# 5 69
How can I assign SimpleXMLElements to variables? 5 67
Formatting issues in XSL FO 3 44
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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