0
          <td>
          <xsl:for-each select="participants/participant">
            <xsl:value-of select="."/>
            <xsl:text> NEW LINE HERE   </xsl:text>
          </xsl:for-each>
          </td>

How can I get a new line where I have the text elements? I can have a space by having a space but I have tried everything to get return character.

Alan Gordon
  • 353
  • 5
  • 14
  • possible duplicate of [Producing a new line in XSLT](http://stackoverflow.com/questions/723226/producing-a-new-line-in-xslt) –  Oct 09 '14 at 16:38
  • Also http://stackoverflow.com/questions/16051402/escaping-new-line-in-xslt. –  Oct 09 '14 at 16:39

2 Answers2

2

Put an actual newline in:

<td>
    <xsl:for-each select="participants/participant">
        <xsl:value-of select="."/>
            <xsl:text>
</xsl:text>
    </xsl:for-each>
</td>

Or, use an escape character such as &#xa;.

  • It's `&x0a;`, but yes. – Boldewyn Oct 09 '14 at 16:31
  • 1
    While `xsl:text` is space-preserving, I would always go with ` ` as that's more resistant to any re-formatting of the XML file. Your example in this answer, for instance, isn't just a newline but a newline followed by four spaces. – Ian Roberts Oct 09 '14 at 16:41
  • this doesn't work at all, just appears as a space still? – Alan Gordon Oct 09 '14 at 19:58
  • @AlanGordon This works perfectly. However, if you're viewing the result in a browser, any sequence of whitespace characters will be collapsed to a single space. Haven't you seen my answer? – michael.hor257k Oct 09 '14 at 20:24
0

If you are producing an HTML table, output a <br/> element (not text) when you want a line break.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51