<BR/> tag in XML content

Discussion in 'XML' started by noor.rahman@gmail.com, Sep 11, 2005.

  1. Guest

    I have an XML file that stores data from an HTML form. I use XSL to
    display the data in HTML format. The data may have newline characters.
    However, XSL is not displaying the newlines properly in the browser.
    I even replaced all the newlines with <BR/> tags but eventhough I see
    the tags in my source, I don't get a line break in the output document.
    Any help would be greatly appreciated.
     
    , Sep 11, 2005
    #1
    1. Advertising

  2. Phlip Guest

    noor.rahman wrote:

    >I have an XML file that stores data from an HTML form. I use XSL to
    > display the data in HTML format. The data may have newline characters.
    > However, XSL is not displaying the newlines properly in the browser.
    > I even replaced all the newlines with <BR/> tags but eventhough I see
    > the tags in my source, I don't get a line break in the output document.
    > Any help would be greatly appreciated.


    If you open the XML in a text editor, the raw text of the <br/> looks like
    &lt;br/&gt; , right?

    Remember that HTML payload in XML is just that - payload. XML will not see
    the well-formed XML tag <br/>, and think "ahah, that's HTML, so copy it out
    raw". It will see a valid XML tag, and won't emit it in the 'text' property
    of the current node.

    Also, depending on the actual XSL plumbing, you might need this attrocity:

    &amp;lt;br/&amp;gt;

    I'm not smart enough to understand if that's a bug or a feature...

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
     
    Phlip, Sep 11, 2005
    #2
    1. Advertising

  3. On Sun, 11 Sep 2005 19:45:05 GMT, "Phlip" <> wrote:

    >I'm not smart enough to understand if that's a bug or a feature...


    I would go further to proclaim that you don't even understand the
    question you commented on :)

    --
    Rex
     
    Jan Roland Eriksson, Sep 12, 2005
    #3
  4. Guest

    thanks to both of you but i still have the problem :):) so what should
    i do to fix it? is there anything/character i can put to insert a
    line-break in xsl?
     
    , Sep 12, 2005
    #4
  5. wrote:
    > I have an XML file that stores data from an HTML form. I use XSL to
    > display the data in HTML format. The data may have newline characters.
    > However, XSL is not displaying the newlines properly in the browser.
    > I even replaced all the newlines with <BR/> tags but eventhough I see
    > the tags in my source, I don't get a line break in the output document.
    > Any help would be greatly appreciated.
    >



    is certainly what you're looking for :

    <xsl:template name="text" match="text()">
    <xsl:param name="text" select="."/>
    <xsl:choose>
    <xsl:when test="contains($text, '
    ')">
    <xsl:value-of select="substring-before($text, '
    ')"/>
    <br/>
    <xsl:call-template name="text">
    <xsl:with-param name="text" select="substring-after($text,
    '
    ')"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="$text"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>

    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------
     
    Philippe Poulard, Sep 12, 2005
    #5
  6. wrote:

    > I have an XML file that stores data from an HTML form. I use XSL to
    > display the data in HTML format. The data may have newline characters.
    > However, XSL is not displaying the newlines properly in the browser.


    XSL is not displaying anything in the browser, the browser displays the
    HTML your XSL produced and thus if you have any HTML display issue you
    need to look into how HTML displays white space like newline characters.

    And HTML's normal rendering of white space is white space collapsing
    meaning whether you author e.g. a paragraph as

    <p>a
    b
    c
    d
    </p>

    or

    <p>a b c d</p>

    the normal rendering will collpase several white space characters in the
    source to one inter-word space so rendering might be alike

    a b c d

    So the solution is to understand how HTML works and if the whitespace in
    an element is to matter then to use for instance the <pre> element e.g.

    <pre>a
    b
    c
    d
    </pre>


    > I even replaced all the newlines with <BR/> tags but eventhough I see
    > the tags in my source, I don't get a line break in the output document.


    We need to see a minimal XSLT stylesheet and minimal XML input to make
    suggestions on what you might be doing wrong in terms of XSLT to have
    <br> elements in HTML output generated with XSLT.

    Or look first at Philippe's answer to find a template that transforms
    text with line breaks into markup with <br/> elements.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Sep 12, 2005
    #6
  7. Guest

    Thanks a lot guys!! Martin, your solutions with <PRE> tags worked like
    a charm and did the trick.
     
    , Sep 12, 2005
    #7
  8. Peter Flynn Guest

    wrote:

    > thanks to both of you but i still have the problem :):) so what should
    > i do to fix it? is there anything/character i can put to insert a
    > line-break in xsl?


    Output a real <br> element to HTML.

    ///Peter
     
    Peter Flynn, Sep 13, 2005
    #8
    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. shruds
    Replies:
    1
    Views:
    870
    John C. Bollinger
    Jan 27, 2006
  2. hazz
    Replies:
    6
    Views:
    49,770
    SkyUCHC
    Jun 9, 2010
  3. Replies:
    4
    Views:
    446
  4. M Wells
    Replies:
    0
    Views:
    144
    M Wells
    Oct 6, 2004
  5. visu
    Replies:
    4
    Views:
    315
Loading...

Share This Page