Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does XSLT add newline (carriage return) in IE10
    primarykey
    data
    text
    <p>This just started with IE10 as far as I can tell.</p> <p>It's not an issue in FF.</p> <p>Using XMLHttpRequest to get some xml data, then display it using xslt...</p> <p>The xslt transformation is automatically adding new lines in seemingly random locations where there is a space in an elements data.</p> <p>If I preview the data using getElementsByTagName, the data is intact, no spaces have been converted to a newlines.</p> <p>Since html treats new lines as a space, you can not see the issue if you simply display the text or place it in an input box, BUT, if the data is stored in a hidden element and you show it using the alert function you can see that there is a newline/carriage return in the output data.</p> <p>The issue seems to be worse if there are NOT carriage returns after the elements in the original xml data. I've actually been able to get around this issue in some cases by adding a carriage return after each element. Some cases, not all.</p> <p>It's almost as if when the transformer is trying to read the data it splits the data at spaces for readability and it automatically adds a carriage return.</p> <p>Example:</p> <h1><strong>xsltTest.htm</strong></h1> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;xslt test&lt;/title&gt; &lt;script type="text/javascript" language="javascript"&gt; function loadFile(f) { xhttp = new window.XMLHttpRequest xhttp.open("GET", f, false) xhttp.setRequestHeader("Cache-Control", "no-cache"); xhttp.setRequestHeader("pragma", "no-cache"); xhttp.send("") //in IE10 this seems to show where the new lines get added alert(xhttp.responseText) var xml = xhttp.responseXML displayData(xml, 'xsltTest.xslt', 'DataDiv') } function displayData(xmlResp, xslFile, targetObj) { var xml = new ActiveXObject("MSXML2.DomDocument"); xml.async = false; xml.load(xmlResp); var xsl = new ActiveXObject("MSXML2.FreeThreadedDomDocument"); xsl.async = false; xsl.load(xslFile); xsl_template = new ActiveXObject("Msxml2.XSLTemplate") xsl_template.stylesheet = xsl; xslProc = xsl_template.createProcessor() xslProc.input = xml xslProc.transform() document.getElementById(targetObj).innerHTML = xslProc.output } function popData(idx,e) { alert(document.getElementById('data_'+idx+'_'+e).value) } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;input type="button" id="WithCRButton" value="Load File WITH CarriageReturns" onclick="loadFile('DataWithCR.xml')" /&gt; &lt;input type="button" id="WithoutCRButton" value="Load File WITHOUT CarriageReturns" onclick="loadFile('DataWithoutCR.xml')" /&gt; &lt;div style="border:1px solid black;width:100%" id="DataDiv"&gt; &lt;/div&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h1><strong>xsltTest.xslt</strong></h1> <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xsl:template match="/"&gt; &lt;table&gt; &lt;xsl:for-each select="TestData/field"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:value-of select="elementData1"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="hidden"&gt; &lt;xsl:attribute name="value"&gt;&lt;xsl:value-of select="elementData1"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="id"&gt;data_&lt;xsl:value-of select="position()"/&gt;_1&lt;/xsl:attribute&gt; &lt;/input&gt; &lt;input type="button" value="show hidden value"&gt; &lt;xsl:attribute name="onclick"&gt;popData('&lt;xsl:value-of select="position()"/&gt;','1')&lt;/xsl:attribute&gt; &lt;/input&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="elementData2"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="hidden"&gt; &lt;xsl:attribute name="value"&gt;&lt;xsl:value-of select="elementData2"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="id"&gt;data_&lt;xsl:value-of select="position()"/&gt;_2&lt;/xsl:attribute&gt; &lt;/input&gt; &lt;input type="button" value="show hidden value"&gt; &lt;xsl:attribute name="onclick"&gt;popData('&lt;xsl:value-of select="position()"/&gt;','2')&lt;/xsl:attribute&gt; &lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <h1><strong>DataWithCR.xml</strong></h1> <pre><code>&lt;TestData&gt; &lt;field&gt; &lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt; &lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt; &lt;/field&gt; &lt;field&gt; &lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt; &lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt; &lt;/field&gt; &lt;field&gt; &lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt; &lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt; &lt;/field&gt; &lt;field&gt; &lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt; &lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt; &lt;/field&gt; &lt;/TestData&gt; </code></pre> <h1><strong>DataWithoutCR.xml</strong></h1> <pre><code>&lt;TestData&gt;&lt;field&gt;&lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt;&lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt;&lt;/field&gt;&lt;field&gt;&lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt;&lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt;&lt;/field&gt;&lt;field&gt;&lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt;&lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt;&lt;/field&gt;&lt;field&gt;&lt;elementData1&gt;ThisHasNoSpaces&lt;/elementData1&gt;&lt;elementData2&gt;ThisHasA Space&lt;/elementData2&gt;&lt;/field&gt;&lt;/TestData&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload