carriage return

Discussion in 'Javascript' started by js, Aug 19, 2004.

  1. js

    js Guest

    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>
    js, Aug 19, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ferdi
    Replies:
    5
    Views:
    4,661
    Jacob Yang [MSFT]
    Aug 24, 2003
  2. Kevin Spencer
    Replies:
    3
    Views:
    3,206
    Doc Wally
    Oct 11, 2003
  3. Jeff Clark
    Replies:
    0
    Views:
    1,594
    Jeff Clark
    Oct 17, 2003
  4. Xeno Campanoli
    Replies:
    0
    Views:
    212
    Xeno Campanoli
    Feb 13, 2006
  5. Steve Anderson
    Replies:
    3
    Views:
    234
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page