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....
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, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br/>
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,
'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
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 />')" />
Re: Replace <br>,</br> tags with <br/> using XSL
You can try this - <xsl:value-of select="translate(., '\n', '<br />')" />