Link to home
Start Free TrialLog in
Avatar of SammyG
SammyG

asked on

Replacing VbCrLf with <br/>

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>
Avatar of RobinPatra
RobinPatra

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
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
Avatar of SammyG

ASKER

Thanks for the reply.

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

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.
Avatar of SammyG

ASKER

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
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
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
Avatar of SammyG

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of RobinPatra
RobinPatra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of SammyG

ASKER

Thanks for the help