Solved

HOWTO replace newline to <BR> with XSL

Posted on 2002-04-16
6
7,711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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
Checkbox and ListView in Android Layout 4 92
Extract XML Data from using TSQL 5 70
ASP.NET reading ATOM 2 74
Cannot open file from ASP if user is "logged in" 13 34
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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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