-1

I am generating an XML that is having CRLF in it

 <col4> 
* Comment # 1
* Comment # 2
* Comment # 2
* Comment # 3
* Comment # 3 edited
</col4>

Now i am transforming it into HTML after transformation the CRLF are missing from output. The output in HTML is generating following (CRLF are missing)

* Comment # 1 * Comment # 2 * Comment # 2 * Comment # 3 * Comment # 3 edited 

I am already using

<xsl:preserve-space elements="*" />

and

<xsl:value-of select="." disable-output-escaping="yes"/>

Kindly tell me how can i retain the CRLF in the output.

Nimble Fungus
  • 513
  • 3
  • 22
  • 1
    HTML 101. Source code layout is not related to screen layout. Line breaks in the source code do not translate to line breaks on the screen. XSLT has nothing to do with that. You are asking the wrong question. – Tomalak Sep 02 '16 at 10:00
  • 1
    If you are outputting HTML, you will need to convert your CRLF characters to `
    ` tags to show the line breaks in HTML. See http://stackoverflow.com/questions/3309746/how-to-convert-newline-into-br-with-xslt for how to do this in XSLT 1.0.
    – Tim C Sep 02 '16 at 10:15
  • Check that your – William Walseth Sep 02 '16 at 11:26
  • **1.** Show us your transformation. -- **2.** Read the [comment above](http://stackoverflow.com/questions/39288976/xslt-removing-the-newline-crlf#comment65913648_39288976) – michael.hor257k Sep 02 '16 at 11:39
  • @William the output method is html () – Nimble Fungus Sep 02 '16 at 11:52
  • @michael.hor257k i have updated the question. i have provided the piece of code. – Nimble Fungus Sep 02 '16 at 12:00
  • 1
    @Tomalak i missed your comment. This helped me fixing the issue – Nimble Fungus Sep 02 '16 at 12:12

2 Answers2

0

Enclose the text in <col4> in <xsl:text>, it should preserve whitespaces.

ljedrz
  • 20,316
  • 4
  • 69
  • 97
0

You'll need to provide some more detail - as you can see from the below, this is not inherent behaviour of an XSLT process.

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<col4> 
* Comment # 1
* Comment # 2
* Comment # 2
* Comment # 3
* Comment # 3 edited
</col4>

XSLT stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
<xsl:output method="html" />

<xsl:template match="col4">
    <p><xsl:value-of select="." /></p>
</xsl:template>

</xsl:stylesheet>

Output:

<p> 
   * Comment # 1
   * Comment # 2
   * Comment # 2
   * Comment # 3
   * Comment # 3 edited 
</p>
Chondrops
  • 728
  • 1
  • 4
  • 14