Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XSLT

Output a Newline From XSLT

0.00/5 (No votes)
6 Dec 2010CPOL 37.8K  
There are many ways to insert a newline in the output of an XSLT, but this is probably the easiest.
There are a few ways of inserting a newline into the output of an XSLT, but most of them make the indentation look weird, require you to remember a strange character entity, or force you to type a bunch. The way I like to do it is to put a newline character into a variable, as follows:
XML
<xsl:variable name="newline"><xsl:text>
</xsl:text></xsl:variable>

You can then use that variable in a variety of ways. Suppose you want to append a newline to the output of this XSLT:
XML
<xsl:value-of select="$someExistingString" />

One way is to select the newline character after you select the existing variable:
XML
<xsl:value-of select="$someExistingString" />
<xsl:value-of select="$newline" />

Alternatively, you can just concatenate it:
XML
<xsl:value-of select="concat($someExistingString, $newline)" />

Like I said, there are alternative ways of doing this. If any of you prefer another technique, feel free to post it here as an alternate to mine.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)