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 <br/> and 
 and 
. 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.
<br/>. 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>
<xsltherwise>
<xsl:value-of select="content"/>
</xsltherwise>
</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>
<xsltherwise><xsl:value-of
select="$formatContent"/></xsltherwise>
</xsl:choose>
</p>
</xsl:template>
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 <br/> and 
 and 
. 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.
<br/>. 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>
<xsltherwise>
<xsl:value-of select="content"/>
</xsltherwise>
</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>
<xsltherwise><xsl:value-of
select="$formatContent"/></xsltherwise>
</xsl:choose>
</p>
</xsl:template>