Solved

HOWTO replace newline to <BR> with XSL

Posted on 2002-04-16
6
7,699 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
3 Use Cases for Connected Systems

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

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Xsl Nested Loop 4 25
Error opening .xml with Excel 2013 4 25
Conditional Formatting 4 35
Post xml via PHP Soap Client 3 37
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…
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, …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

932 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

16 Experts available now in Live!

Get 1:1 Help Now