Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1024
  • Last Modified:

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>
0
SammyG
Asked:
SammyG
  • 6
  • 4
1 Solution
 
RobinPatraCommented:
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
 
RobinPatraCommented:
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
 
SammyGAuthor Commented:
Thanks for the reply.

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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RobinPatraCommented:
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
 
SammyGAuthor Commented:
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
 
RobinPatraCommented:
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
 
RobinPatraCommented:
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
 
SammyGAuthor Commented:
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
 
RobinPatraCommented:
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
 
b1xml2Commented:
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
 
SammyGAuthor Commented:
Thanks for the help
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now