nl2br
HTML Line Breaks
Description
Inserts HTML line breaks before all newlines in a string.
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Example: <xsl:call-template name="nl2br"> <xsl:with-param name="string" select="body"/> </xsl:call-template> --> <xsl:template name="nl2br"> <xsl:param name="string"/> <xsl:value-of select="normalize-space(substring-before($string,' '))"/> <xsl:choose> <xsl:when test="contains($string,' ')"> <br /> <xsl:call-template name="nl2br"> <xsl:with-param name="string" select="substring-after($string,' ')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>