Results 1 to 4 of 4

Thread: Replace <br>,</br> tags with <br/> using XSL

  1. #1
    Join Date
    Feb 2009
    Posts
    66

    Replace <br>,</br> tags with <br/> using XSL

    hie friends,

    I want to change the HTML tags <br> and </br> which are responsible to break the paragraph or starting a sentence from the new line, with something like <br/> using XSL. Is it possible to replace these break tags (<br> & </br>) with <br/>. How can I do the same ?
    any ideas....

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Replace <br>,</br> tags with <br/> using XSL

    Check this -

    Code:
    <xsl:template match="text()">
       <xsl:call-template name="break">
    </xsl:template>
    
    <xsl:template name="break">
       <xsl:param name="text" select="."/>
       <xsl:choose>
       <xsl:when test="contains($text, '&#xa;')">
          <xsl:value-of select="substring-before($text, '&#xa;')"/>
          <br/>
          <xsl:call-template name="break">
              <xsl:with-param name="text" select="substring-after($text,
    '&#xa;')"/>
          </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
    	<xsl:value-of select="$text"/>
       </xsl:otherwise>
       </xsl:choose>
    </xsl:template>

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Replace <br>,</br> tags with <br/> using XSL

    In my XML script, I have tried this:

    <xsl:template match="myelem">
    <div>
    <xsl:value-of select="translate(., '\n', '<br />')" />
    </div>
    </xsl:template>

    But I get the folllowing error:

    The character '<' cannot be used in an attribute value.
    Error processing resource 'http://localhost/test.xml'...
    <xsl:value-of select="translate(., '\n', '<br />')" />

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Replace <br>,</br> tags with <br/> using XSL

    You can try this - <xsl:value-of select="translate(., '\n', '&lt;br /&gt;')" />

Similar Threads

  1. How to add tags to PDF and txt files
    By Vincent D in forum Windows Software
    Replies: 5
    Last Post: 15-04-2011, 10:17 AM
  2. Javascript - replace HTML tags with spaces
    By Jensen Ackles in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 12:10 PM
  3. What are an ID3 tags in PHP?
    By Jacques25 in forum Software Development
    Replies: 4
    Last Post: 28-02-2010, 03:36 AM
  4. <br /> Tags are being ignored by IE7
    By Carey in forum Software Development
    Replies: 5
    Last Post: 30-12-2009, 10:58 PM
  5. Tags (or tags) PHP
    By Gyan Guru in forum Guides & Tutorials
    Replies: 2
    Last Post: 22-12-2008, 01:04 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,910,459.12180 seconds with 16 queries