[XSLT] Valid XHTML

Discussion in 'XML' started by Greg, Sep 26, 2003.

  1. Greg

    Greg Guest

    Hi everybody,

    so, I would like to use XML files for some parts of my website. I would like
    to respect W3C XHTML 1.1 recommendation.
    Then, I have these two docs :
    o My XML file:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>

    <catalog>
    <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
    </cd>

    [...]

    <cd>
    <title>Unchain my heart</title>
    <artist>Joe Cocker</artist>
    <country>USA</country>
    <company>EMI</company>
    <price>8.20</price>
    <year>1987</year>
    </cd>
    </catalog>

    o My XSL stylesheet:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>
    <xsl:template match="/">
    <html>
    <body>
    <h2>My CD Collection</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
    <th align="left">Title</th>
    <th align="left">Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
    <td><xsl:value-of select="title"/></td>
    <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    As it's writen in W3C website
    (http://www.w3.org/TR/xslt#section-XML-Output-Method):
    "If the doctype-system attribute is specified, the xml output method should
    output a document type declaration immediately before the first element."

    But W3C validator (http://validator.w3.org/) tells me that my XML file is
    not valid:
    Fatal Error: No DOCTYPE specified!

    My question is: What did I do or what I did not do ?

    You can find those two exemple at that address:
    http://bimyou.free.fr/xmltest/cdcatalog.xml

    Thanks

    Greg
     
    Greg, Sep 26, 2003
    #1
    1. Advertisements

  2. Change:
    to:
    <html xmlns="http://www.w3.org/1999/xhtml">

    but then you'll find other errors -- e.g. no "head" is present in the output
    of the transformation.


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL


     
    Dimitre Novatchev, Sep 26, 2003
    #2
    1. Advertisements

  3. Greg

    Greg Guest

    Greg, Sep 26, 2003
    #3
  4. I forgot to tell you to add:

    encoding="ASCII"

    to your xsl:eek:utput


    Then I pass the result to the validater and get:

    This page is not Valid XHTML 1.0 Transitional!
    Below are the results of attempting to parse this document with an SGML
    parser.

    1.. Line 4, column 5: document type does not allow element "body" here
    (explain...).
    <body>
    ^2.. Line 21, column 6: end tag for "html" which is not finished
    (explain...).
    </html>
    ^Source Listing
    Below is the source input I used for this validation:

    1: <?xml version="1.0" encoding="ASCII"?>
    2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3: <html xmlns="http://www.w3.org/1999/xhtml">
    4: <body>
    5: <h2>My CD Collection</h2>
    6: <table border="1">
    7: <tr bgcolor="#9acd32">
    8: <th align="left">Title</th>
    9: <th align="left">Artist</th>
    10: </tr>
    11: <tr>
    12: <td>Empire Burlesque</td>
    13: <td>Bob Dylan</td>
    14: </tr>
    15: <tr>
    16: <td>Unchain my heart</td>
    17: <td>Joe Cocker</td>
    18: </tr>
    19: </table>
    20: </body>
    21: </html>
    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
     
    Dimitre Novatchev, Sep 26, 2003
    #4
  5. Greg

    Greg Guest

    I forgot to tell you to add:
    [SNIP]

    Maybe that's the problem. I use my XML file directly, but you seem to use a
    XHTML file resulting from my two files, or am I totally wrong.
    Does the validator can validate XML files directly?
     
    Greg, Sep 27, 2003
    #5
  6. Maybe that's the problem. I use my XML file directly, but you seem to use
    a
    Why do you intednd to XHTML-validate *any* xml???

    The idea behind XHTML validation is to see whether or not the input is valid
    according to the XHTML schema.

    Obviously, feeding the XHTML validator with *any* xml will return
    "invalid" -- therefore it's waste of time to do it.

    What may only be useful is to check whether the result of your xslt
    transformation (which is supposed to generate XHTML) is really valid XHTML.

    Remember, validation is checking against a schema -- it is not just checking
    to see if some text is well-formed xml. A valid document must be well-formed
    but not every well-formed document is valid.

    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
     
    Dimitre Novatchev, Sep 27, 2003
    #6
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.