carriage return

J

js

Hi,
This may not so much related to this group than xslt group, but just
desparately need to get the problem solved. So here it goes.

I have an XML document like the following. I use xsl to output the
html code. However, <br/> is always shown as is instead of a carriage
return. I've tried using &lt;br/&gt; and &#x0D and &#x0A. None of
these escape sequence worked. They all show up as typed. In addition,
the carriage return in the content would also cause the javascript
"unterminated string constant" error. I would appreciate if anyone
could help. Thanks.


XML
====

<root>
<news>
<content>The first paragraph with \'carriage return\' in single
quote.<br/> The second paragraph with \"carriage return\" in double
quote. <br/> The last paragraph.
</content>
</news>
<news>
<content>The first paragraph with \'carriage return\' escaped.

The second paragraph with \"carriage return\" escaped.
</content>
</news>
<news>
<content>The first paragraph with \'carriage return\' escaped.
&lt;br/&gt;. The second paragraph with \"carriage return\" escaped.

</content>
</news>

</root>

Partial xslt
============
<xsl:template match="/root/news">
<xsl:variable name="displayLength">200</xsl:variable>
<xsl:variable name="formatContent">
<xsl:choose>
<xsl:when test='contains(content,"\")'>
<xsl:value-of disable-output-escaping="yes"
select='translate(content,"\","")'/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="content"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>


<p id="partialText" style="padding-left:10px">
<xsl:choose>
<xsl:when test="string-length(.)> $displayLength">
<xsl:value-of select="substring($formatContent,1,$displayLength)"/>...
<img id="ImgClickHere" src="/images/epingle.gif" alt="more"
height="15" width="15" align="top" title="click for full content">
<xsl:attribute name="onmouseover">this.style.cursor='hand'</xsl:attribute>
<xsl:attribute name="onclick">
var strContent = "<xsl:value-of select="content"/>";
var oContent = document.getElementById("moreNews");
var oFullContent = document.getElementById("fullContent");

oFullContent.innerHTML=strContent;
getPos(event);
with (oContent.style)
{
top = eTop;
left = eLeft;
display = 'block';
}
</xsl:attribute>
</img>
</xsl:when>
<xsl:eek:therwise><xsl:value-of
select="$formatContent"/></xsl:eek:therwise>
</xsl:choose>
</p>
</xsl:template>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,230
Latest member
LifeBoostCBD

Latest Threads

Top