I've been doing a lot of work trying to figure out how to view a XML file (on Internet Explorer) using a style sheet, and retain carriage returns / linefeeds from the document.
I did make it work, but didn't want to use tons of CDATA with [br/] all over my XML file. I was hoping to use the saved carriage returns in the XML text file.
I saw other examples such as this one: how to convert NEWLINE into <BR/> with XSLT? but I'm not very good at XML/XSL and couldn't figure out how to make it work right. Everything I did it had the placed a "& lt;br/& gt;" or a CR/LF but not a < br > that the browser could understand.
XSL file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body style="font-family:verdana;">
<h2>Example</h2>
<table border="1" bordercolor="#000000" cellspacing="0">
<tr bgcolor="#000000" style="color:#FFFFFF;text-align:left;font-size:80%">
<th>#</th>
<th>Has <![CDATA["CDATA[<br/>]"]]> (It Works)</th>
<th>Has <![CDATA["
"]]> (Want this one as worst case)</th>
<th>Has Carriage Return (Want this one to work)</th>
</tr>
<xsl:for-each select="report/test">
<tr style="text-align:left;font-size:80%">
<xsl:choose>
<xsl:when test="@type = 'append_text'">
<td><b><xsl:value-of select="text"/></b></td>
</xsl:when>
<xsl:when test="@type = 'test_step'">
<td id="ref{num}"><xsl:value-of select="num"/></td>
<td><xsl:value-of select="hasBR" disable-output-escaping="yes"/></td>
<td><xsl:value-of select="hasXA" disable-output-escaping="yes"/></td>
<td><xsl:value-of select="hasCR" disable-output-escaping="yes"/></td>
</xsl:when>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="51380-200.xsl"?>
<report>
<test type="test_step">
<num>1</num>
<hasXA>Line 1 
 Line 2 
 Line 3</hasXA>
<hasBR>Line 1 <![CDATA[<br/>]]> Line 2 <![CDATA[<br/>]]> Line 3</hasBR>
<hasCR>Line 1
Line2
Line3</hasCR>
</test>
<test type="test_step">
<num>2</num>
<hasXA>Line 1 
 Line 2 
 Line 3</hasXA>
<hasBR>Line 1 <![CDATA[<br/>]]> Line 2 <![CDATA[<br/>]]> Line 3</hasBR>
<hasCR>Line 1
Line2
Line3</hasCR>
</test>
<test type="test_step">
<num>3</num>
<hasXA>Line 1 
 Line 2 
 Line 3</hasXA>
<hasBR>Line 1 <![CDATA[<br/>]]> Line 2 <![CDATA[<br/>]]> Line 3</hasBR>
<hasCR>Line 1
Line2
Line3</hasCR>
</test>
</report>
I greatly appreciate the help!
Note, I've been using XSL transform.net to try to make it work. I loaded a version of it on it. http://xsltransform.net/bESZULX
is . I use
throughout my programs without an issue. – William Walseth Feb 22 '19 at 04:55