Solved

HOWTO replace newline to <BR> with XSL

Posted on 2002-04-16
6
7,696 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
Comment Utility
jussara
You may want to try the replace with <BR /> instead

Hope this helps
Ivanc
0
 
LVL 1

Expert Comment

by:RobinPatra
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now