[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Replace new lines by <br> and double quote with s

Subject: RE: Replace new lines by <br> and double quote with special char: Problem retaining HTML tags
From: <Ambika.Das@xxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Sep 2006 10:02:42 +0530
replace newline with br
Hi David,

The XSL I have used is given below.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no"/>

  <xsl:template match="elem">
   <xsl:text>&#10;Elem Id, News Details&#10;</xsl:text>
   <xsl:value-of select="@id"/>
   <xsl:text>, "</xsl:text>
   <xsl:apply-templates select="text/*"/>
   <xsl:text>"</xsl:text>
  </xsl:template>


   <xsl:template match="text()">
    <xsl:call-template name="transformXMLString">
      <xsl:with-param name="StringToTransform" select="."/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template  name="transformXMLString">
   <xsl:param name="StringToTransform" select="."/>
   <xsl:value-of
select="translate($StringToTransform,'&#10;&quot;','@!')"/>
  </xsl:template>
</xsl:stylesheet>

I am getting the following output.


Elem Id, News Details
1234, "    This is some data          This is some special characters
&lt;AHLN.AS&gt;     A group of students have gone to picnic.          **
This is another special tag@     @ @  "

I am not able to retain the HTML tags. The output should be as follows.

Elem Id, News Details
1234, "<p>    This is some data </p><br><p></p><br><p>    This is some
special characters &lt;AHLN.AS&gt; </p><br><p>    A group of students
have gone to picnic. </p><br><p>     </p><br><PRE>    ** This is another
special tag<br></PRE></text><br></elem>"

Line breaks should be replaced by <br> and HTML tags retained as it is.
It should be CSV like output.

Thanks & Regards,
Ambika Prasad Das


-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Friday, September 08, 2006 8:37 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Replace new lines by <br> and double quote with
special char: Problem retaining HTML tags



> I have tried David's code. But the output is required in a particular
> format since the output is the input for another application

In my reply I said

> You just need to fill in the replace template and templates for any
> elements that you need to process by somthing other than copy.

which in this case means adding a template for elem
something like this

  <xsl:template match="elem">
   <xsl:text>&#10;Elem Id, News Details&#10;</xsl:text>
   <xsl:value-of select="@id"/>
   <xsl:text>, "</xsl:text>
   <xsl:apply-templates select="text/*"/>
   <xsl:text>"</xsl:text>
  </xsl:template>

and a template for the replace, something like this (which isnt the
replace you wanted but fits on one line so does as an example)

  <xsl:template  name="transformXMLString">
   <xsl:param name="StringToTransform" select="."/>
   <xsl:value-of
select="translate($StringToTransform,'&#10;&quot;','@!')"/>
  </xsl:template>

Then it appears that you want the line breaks in all elements (eg
<pre>). changing, not just those below <p> so change
  <xsl:template match="p//text()">
to
  <xsl:template match="text()">
so thattemplate matches all text nodes.

Then the code that I posted before on the input that you just posted
produces the following which looks fairly close to what you want to me:

 saxon grumble.xml grumble.xsl

Elem Id, News Details
1234, "<p>    This is some data </p><p>     </p><p>    This is some
special characters &lt;AHLN.AS&gt; </p><p>    A group of students have
gone to picnic. </p><p>     </p><PRE>    ** This is another special tag@
@ @  </PRE>"

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.