How do I preserve things like tabs and carriage returns in text? when transforming XML to XHTML with XSL. For example:
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="article.xsl"?>
<content>
<article name="Test Article">
<heading>Test Article</heading>
<subheading>Special Chars</subheading>
<paragraph>
<text>
a less than <
a greater than >
</text>
<text type="code">
some code.
</text>
</paragraph>
</article>
</content>
XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="content">
<xsl:apply-templates select="article" />
</xsl:template>
<xsl:template match="article">
<h2><xsl:value-of select="heading" /></h2>
<xsl:value-of select="subheading" />
<xsl:for-each select="paragraph">
<p>
<xsl:for-each select="text">
<xsl:choose>
<xsl:when test="@type = 'link'">
<a href="{@href}" target="{@target}">
<xsl:value-of select="." />
</a>
</xsl:when>
<xsl:when test="@type = 'code'">
<div class="code">
<xsl:value-of select="." />
</div>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The carriage return between the text line:
a less than <
And
a greater than >
is lost when rendered in the browser, I sort of understand why that is, but I don't know how to apply XML or XSL to include/preserve or force the carriage return.