Solved

Replacing VbCrLf with <br/>

Posted on 2002-04-16
11
986 Views
Last Modified: 2008-03-03
Hi There

I am looking for a way to replace carriage returns, VbCrLf or any equivalent, with <br> or <p> tags. The current transformation renders a single line and all paragraph formatting is lost when displayed as html.

Cheers,

S

Here is my XML:
<Institutes>
     <Data>
          <Item intInstituteId="31" intClientId="1" strInstitute="Afrox Healthcare Ltd." strPhysAddStreet="91 Gliddin" strPhysAddCity="London" strPhysAddCode="W14 8YB" strPostAddStreet="91 Gliddin St" strPostAddCity="London" strPostAddCode="W14 9YB" strTelephoneNr="020 8748 9714" strFaxNr="020 8748 9714"/>
          <Item intInstituteId="32" intClientId="1" strInstitute="This is line 1
This is line 2
This is line 3
This is line 4"/>
          <Item intInstituteId="33" intClientId="1" strInstitute="Test"/>
     </Data>
</Institutes>

Here is a stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" />
<xsl:template match="/">
     <xsl:value-of select="//Item[@intInstituteId='32']/@strInstitute" />
</xsl:template>
</xsl:stylesheet>
0
Comment
Question by:SammyG
  • 6
  • 4
11 Comments
 
LVL 1

Expert Comment

by:RobinPatra
Comment Utility
Dear SammyG;

Let one xml file be in this format
***********************************

<sample>
     &lt;br&gt;My Name is XXX &lt;/br&gt;
     &lt;br&gt;I work for YYY &lt;/br&gt;
     &lt;br&gt;I am from ZZZ &lt;/br&gt;
</sample>

**********************************************

for getting the ouput the way u required is
 My name is XXX
 I work for YYYY
 I am from ZZZZ

So the required XSL for it is
********************************

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/>
<xsl:template match="/">
     <xsl:value-of select="/sample" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>

****************************

so in the XPATH of ur XSL in the XSL:Value of tag u have to include another attribute that is
"disable-output-escaping" with value as "yes" it will maintain anything like ur vbcrlf or <br> or <p>


I think this might solve ur problem

Any further queries is most welcome

Regards
Robin
0
 
LVL 1

Expert Comment

by:RobinPatra
Comment Utility
Dear SammyG;

Let one xml file be in this format
***********************************

<sample>
     &lt;br&gt;My Name is XXX &lt;/br&gt;
     &lt;br&gt;I work for YYY &lt;/br&gt;
     &lt;br&gt;I am from ZZZ &lt;/br&gt;
</sample>

**********************************************

for getting the ouput the way u required is
 My name is XXX
 I work for YYYY
 I am from ZZZZ

So the required XSL for it is
********************************

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/>
<xsl:template match="/">
     <xsl:value-of select="/sample" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>

****************************

so in the XPATH of ur XSL in the XSL:Value of tag u have to include another attribute that is
"disable-output-escaping" with value as "yes" it will maintain anything like ur vbcrlf or <br> or <p>


I think this might solve ur problem

Any further queries is most welcome

Regards
Robin
0
 

Author Comment

by:SammyG
Comment Utility
Thanks for the reply.

I would like to keep the XML in its original format though.

0
 
LVL 1

Expert Comment

by:RobinPatra
Comment Utility
Ok;
<Item intInstituteId="32" intClientId="1" strInstitute="This is line 1
This is line 2
This is line 3
This is line 4"/>


I suppose the attribute "strInstitute" value should have those html tags for next line or parameters otherwise how could u depict them in ur XSl for output as html.

Then only urs "disable-output-escaping" attribute of "xsl:value" tag will take care of maintaing their identity in the output.

If i am out of track can u be bit more elaborative to solve ur quiery.
0
 

Author Comment

by:SammyG
Comment Utility
Lets say you have a textarea and you enter some text into it. That text may include carriage returns. That text is then entered into a db. If you retrieve the text and want to display it in HTML, keeping the same paragraph formatting, you need to replace the VbCrLf with <br>

In ASP this is done using a simple replace(strText, VbCrlf, "<br>") function. I am looking for the XSL equivalent.

Hope that is more clear.

Cheers,

Sammy
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 1

Expert Comment

by:RobinPatra
Comment Utility
Dear SammyG,

One more clarification is required from u.
Are you storing the TEXT in the TEXT AREA as a "PROPER I MEAN VALID XML FILE" in the database.

Robin
0
 
LVL 1

Expert Comment

by:RobinPatra
Comment Utility
Dear SammyG,

One more clarification is required from u.
Are you storing the TEXT in the TEXT AREA as a "PROPER I MEAN VALID XML FILE" in the database.

Robin
0
 

Author Comment

by:SammyG
Comment Utility
Robin

No it goes into the database as a normal string value, and comes out as a XML string converted from an ADO Recordset.

Cheers,

SG
0
 
LVL 1

Accepted Solution

by:
RobinPatra earned 50 total points
Comment Utility
Ok SG
When your are entering ur record to the database .I suppose u might be replacing the vbCrlf between the lines to another character let it be "¢Õ",then only whole the value that is in the string can be inserted to database.Am i right?

So when u r again retriveing it from the database for generating the XML replace the character("¢Õ") with <br>.

And in the XSL for xsl:value tag add a attribute called

"disable-output-escaping" and set its value to "yes" for refelecting the nature of "<br>".

I think this might help u up.

Robin
0
 
LVL 23

Expert Comment

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

Author Comment

by:SammyG
Comment Utility
Thanks for the help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

12 Experts available now in Live!

Get 1:1 Help Now