Solved

Replacing VbCrLf with <br/>

Posted on 2002-04-16
11
1,000 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
ID: 6944551
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
ID: 6944572
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
ID: 6944592
Thanks for the reply.

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

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Expert Comment

by:RobinPatra
ID: 6944674
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
ID: 6944716
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
 
LVL 1

Expert Comment

by:RobinPatra
ID: 6947077
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
ID: 6947133
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
ID: 6947148
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
ID: 6947330
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
ID: 6947462
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
ID: 6947512
Thanks for the help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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