Solved

Replacing VbCrLf with <br/>

Posted on 2002-04-16
11
987 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
 
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
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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

24 Experts available now in Live!

Get 1:1 Help Now