Skip to content

Instantly share code, notes, and snippets.

@Svel
Created May 7, 2011 03:34
Show Gist options
  • Save Svel/960176 to your computer and use it in GitHub Desktop.
Save Svel/960176 to your computer and use it in GitHub Desktop.
XSL template method to convert new lines into <br /> tag
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="windows-1251" indent="yes" />
<xsl:template name="break">
<xsl:param name="text" />
<xsl:choose>
<xsl:when test="contains($text,'&#xa;')">
<xsl:value-of select="substring-before($text, '&#xa;')" disable-output-escaping="yes" />
<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" disable-output-escaping="yes" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment