Click here to Skip to main content
15,886,799 members
Articles / Programming Languages / XSLT
Tip/Trick

Output a Newline From XSLT

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
6 Dec 2010CPOL 37.3K   3  
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)


Written By
Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with ASP.net and you don't read that, you are dead to me).
  • Graduated summa cum laude with a BS in Computer Science.
  • Wrote some articles and some tips.
  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.
  • Software I have donated to (you should too):

Comments and Discussions

 
-- There are no messages in this forum --