xslt, output closed tags

Discussion in 'XML' started by Jesper Moth, Sep 19, 2003.

  1. Jesper Moth

    Jesper Moth Guest

    The MSXML4 xslt-parser would output any source <div/> like this:

    <div></div>

    I never figured out how to disable this behaviour. But since it makes the
    source document look cleaner, and since most browsers require empty divs to
    be markup up this way, I didn't really give it an extra thought untill I
    moved to the Tomcat 4.1 where the *reverse* situation applies. The native
    xslt-parser outputs any <div></div> like this:

    <div/>

    - effectively misrendering the page in certain important browsers. And it's
    not just the content of the source document that outputs like this; it's
    also the content of the templates themselves:

    <xsl:template match="/">
    <div>
    <h1>Hello</h1>
    <div></div> <!-- this becomes <div/> in output -->
    <div>
    <xsl:template>

    My first thought was to change the output method to HTML, but amazingly
    this didn't change anything; and I would also like to avoid this. I have no
    idea on how to go about this and I can't figure out how the spec is
    supposed to be read on this subject. What I would like is to have my
    source-file <input/> elements and my <div></div> elements rendered exactly
    like that [transforming xhtml2 to xhtml1]. Here is my output tag:

    <xsl:eek:utput
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    method="xml"
    encoding="UTF-8"
    omit-xml-declaration="no"
    indent="yes" />


    --
    Jesper Moth
    Jesper Moth, Sep 19, 2003
    #1
    1. Advertising

  2. Jesper Moth wrote:

    > The MSXML4 xslt-parser would output any source <div/> like this:
    >
    > <div></div>
    >
    > I never figured out how to disable this behaviour. But since it makes the
    > source document look cleaner, and since most browsers require empty divs to
    > be markup up this way, I didn't really give it an extra thought untill I
    > moved to the Tomcat 4.1 where the *reverse* situation applies. The native
    > xslt-parser outputs any <div></div> like this:
    >
    > <div/>
    >
    > - effectively misrendering the page in certain important browsers. And it's
    > not just the content of the source document that outputs like this; it's
    > also the content of the templates themselves:
    >
    > <xsl:template match="/">
    > <div>
    > <h1>Hello</h1>
    > <div></div> <!-- this becomes <div/> in output -->
    > <div>
    > <xsl:template>
    >
    > My first thought was to change the output method to HTML, but amazingly
    > this didn't change anything; and I would also like to avoid this. I have no
    > idea on how to go about this and I can't figure out how the spec is
    > supposed to be read on this subject. What I would like is to have my
    > source-file <input/> elements and my <div></div> elements rendered exactly
    > like that [transforming xhtml2 to xhtml1]. Here is my output tag:
    >
    > <xsl:eek:utput
    > doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    > doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    > method="xml"
    > encoding="UTF-8"
    > omit-xml-declaration="no"
    > indent="yes" />


    Consider to use
    <xsl:eek:utput method="html"
    that way you should have no problems with HTML browsers.
    Only XSLT 2 has
    <xsl:eek:utput method="xhtml"
    to produce XHTML that is backwards compatible to HTML browsers.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 19, 2003
    #2
    1. Advertising

  3. Jesper Moth

    Jesper Moth Guest

    Martin Honnen wrote

    > Consider to use
    > <xsl:eek:utput method="html"
    > that way you should have no problems with HTML browsers.
    > Only XSLT 2 has
    > <xsl:eek:utput method="xhtml"
    > to produce XHTML that is backwards compatible to HTML browsers.


    Thanks Martin. Weird thing is that a "html" output does not prevent empty
    elements from being closed xml-style in the Tomcat native parser. It will
    also not impress the ladies.

    I wrote some templates to fix the problem for now [adding whitespace
    content to script, textarea and iframe elements]. If I can figure out how
    to upgrade these Xerces and Xalan compontents I can always hope that they
    behave differently in this respect; after all, the MSXML parser got it
    right without any extra effort [usually this implies that it got it wrong
    according to specs, but I can't say for sure in this case]. Thanks again!


    --
    Jesper Moth
    Jesper Moth, Sep 19, 2003
    #3
    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. Dean H. Saxe
    Replies:
    0
    Views:
    1,028
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    722
    Rob Nicholson
    May 28, 2005
  3. Mark
    Replies:
    0
    Views:
    680
  4. Replies:
    0
    Views:
    3,571
  5. Matt Kruse
    Replies:
    5
    Views:
    309
    Richard Cornford
    Sep 9, 2003
Loading...

Share This Page