self-closing tags

Discussion in 'XML' started by David Schwartz, Mar 7, 2008.

  1. My xsl includes image tags as follows:

    <img src="../images/u.gif" width="16" height="16" alt="Back to top"
    border="0"/>

    Yet, after processing, the img tag is no longer self-closing so it's
    not well-formed.

    Can someone tell me what's going on and how to fix?

    FYI, I'm using XALAN v.2.7.0

    TIA,
    David
    David Schwartz, Mar 7, 2008
    #1
    1. Advertising

  2. David Schwartz wrote:
    > My xsl includes image tags as follows:
    >
    > <img src="../images/u.gif" width="16" height="16" alt="Back to top"
    > border="0"/>
    >
    > Yet, after processing, the img tag is no longer self-closing so it's
    > not well-formed.


    "well-formed" is defined for XML and with XML
    <img />
    as well as
    <img/>
    as well as
    <img></img>
    _is_ well-formed.

    If you want to generate HTML with your stylesheet then you want
    <img>
    and that is achieved by using
    <xsl:eek:utput method="html"/>
    and by making sure your result elements are in no namespace.





    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 7, 2008
    #2
    1. Advertising

  3. On Mar 7, 9:47 am, Martin Honnen <> wrote:
    > David Schwartz wrote:
    > > My xsl includes image tags as follows:

    >
    > > <img src="../images/u.gif" width="16" height="16" alt="Back to top"
    > > border="0"/>

    >
    > > Yet, after processing, the img tag is no longer self-closing so it's
    > > not well-formed.

    >
    > "well-formed" is defined for XML and with XML
    > <img />
    > as well as
    > <img/>
    > as well as
    > <img></img>
    > _is_ well-formed.
    >
    > If you want to generate HTML with your stylesheet then you want
    > <img>
    > and that is achieved by using
    > <xsl:eek:utput method="html"/>
    > and by making sure your result elements are in no namespace.
    >


    I am using <xsl:eek:utput method="html"/>. Also, I'm looking for xhmtl so
    <img> by itself won't do and, as I understand it anyway, not well-
    formed in that context. Any thoughts what might be going on?

    My result elements are not in a namespace. FWIW, here are the
    stylesheet and output elements (I use the redirect to produce the
    output files):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform" xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
    extension-element-prefixes="redirect">
    <!-- <xsl:eek:utput method="html" version="4.0" indent="yes"
    encoding="ISO-8859-1"/> -->
    <xsl:eek:utput method="xml" omit-xml-declaration="yes" version="4.0"
    indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    encoding="ISO-8859-1"/>


    Thanks for the help.

    David
    David Schwartz, Mar 7, 2008
    #3
  4. David Schwartz wrote:

    > I am using <xsl:eek:utput method="html"/>. Also, I'm looking for xhmtl so
    > <img> by itself won't do and, as I understand it anyway, not well-
    > formed in that context. Any thoughts what might be going on?


    specifying method="html" tells the xslt system that you do not want xml
    syntax, you want html syntax, so specify method="xml" if that's what you
    want.

    > My result elements are not in a namespace. FWIW, here are the
    > stylesheet and output elements (I use the redirect to produce the
    > output files):


    If the result elements are not in a namespace then they are not xhtml,
    whatever syntax is used for empty elements, so add
    xmlns="http://www.w3.org/1999/xhtml"
    to your xsl:stylesheet element.
    This will also have the effect of making the default serialisation xml
    as the html serialisation the default, ashtml is only the default output
    method if the top level element is html in no namespace.
    >
    > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    > Transform" xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
    > extension-element-prefixes="redirect">
    > <!-- <xsl:eek:utput method="html" version="4.0" indent="yes"
    > encoding="ISO-8859-1"/> -->
    > <xsl:eek:utput method="xml" omit-xml-declaration="yes" version="4.0"
    > indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    > encoding="ISO-8859-1"/>
    >
    >
    > Thanks for the help.
    >
    > David


    David

    --
    http://dpcarlisle.blogspot.com
    David Carlisle, Mar 7, 2008
    #4
  5. I added the namespace attribute as you suggested. Sure enough, the
    image tags are self-closing now. However, now every resulting element
    has the following: div xmlns=""

    David
    David Schwartz, Mar 8, 2008
    #5
  6. David Schwartz wrote:
    > I added the namespace attribute as you suggested. Sure enough, the
    > image tags are self-closing now. However, now every resulting element
    > has the following: div xmlns=""


    If you want to put all result elements in the namespace
    http://wwww.w3.org/1999/xhtml then put that declaration on the
    xsl:stylesheet element
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns="http://www.w3.org/1999/xhtml">



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 8, 2008
    #6
  7. David Schwartz wrote:
    > I added the namespace attribute as you suggested. Sure enough, the
    > image tags are self-closing now. However, now every resulting element
    > has the following: div xmlns=""
    >
    > David


    That means that you have generated the div in no namespace instead of
    the xhtml namespace. If you have declared the xhtml namespace on
    xsl:stylesheet then elements created in the stylesheet will be xhtml
    (unless you work hard to stop that) so perhaps these div elements have
    been copied from an input document?
    If the input is in no-namespace and you want to generate elements in the
    xhtml namepsace, you don't want to copy with xsl:copy or xsl:copy-of you
    want to generate an element in the (new) default namespace but wth the
    same local name as before, so don't use
    <xsl:copy>
    use
    <xsl:element name="{local-name()}">

    David


    --
    http://dpcarlisle.blogspot.com
    David Carlisle, Mar 8, 2008
    #7
    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. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    556
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    577
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    387
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    357
    falcon
    Jul 31, 2005
  5. Bart Kastermans
    Replies:
    6
    Views:
    383
    Bart Kastermans
    Jul 13, 2008
Loading...

Share This Page