[XSLT] Valid XHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg

    #1

    [XSLT] Valid XHTML

    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>Columb ia</company>
    <price>10.90</price>
    <year>1985</year>
    </cd>

    [...]

    <cd>
    <title>Unchai n 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:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
    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="#9acd3 2">
    <th align="left">Ti tle</th>
    <th align="left">Ar tist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
    <td><xsl:valu e-of select="title"/></td>
    <td><xsl:valu e-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:


    Thanks

    Greg


  • Dimitre Novatchev

    #2
    Re: [XSLT] Valid XHTML

    Change:
    [color=blue]
    > <html>[/color]

    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


    "Greg" <gfaudet@enib.f r> wrote in message
    news:3f744a79$0 $10410$626a54ce @news.free.fr.. .[color=blue]
    > Hi everybody,
    >
    > so, I would like to use XML files for some parts of my website. I would[/color]
    like[color=blue]
    > 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>Columb ia</company>
    > <price>10.90</price>
    > <year>1985</year>
    > </cd>
    >
    > [...]
    >
    > <cd>
    > <title>Unchai n 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:styleshe et version="1.0"
    > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    > <xsl:output method="xml"
    > doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
    > 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="#9acd3 2">
    > <th align="left">Ti tle</th>
    > <th align="left">Ar tist</th>
    > </tr>
    > <xsl:for-each select="catalog/cd">
    > <tr>
    > <td><xsl:valu e-of select="title"/></td>
    > <td><xsl:valu e-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[/color]
    should[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Greg

      #3
      Re: [XSLT] Valid XHTML

      "Dimitre Novatchev" <dnovatchev@yah oo.com> a écrit dans le message de news:
      bl1t9h$6qf57$1@ ID-152440.news.uni-berlin.de...[color=blue]
      > Change:
      >[color=green]
      > > <html>[/color]
      >
      > to:
      > <html xmlns="http://www.w3.org/1999/xhtml">
      >
      > but then you'll find other errors -- e.g. no "head" is present in the[/color]
      output[color=blue]
      > of the transformation.[/color]

      Thanks, but after changing it, I still get the same error: "Fatal Error: No
      DOCTYPE specified!".
      http://validator.w3.org/check?uri=ht...Fcdcatalog.xml

      Like if the doctype-system/public won't work...?

      [SNIP]


      Comment

      • Dimitre Novatchev

        #4
        Re: [XSLT] Valid XHTML

        I forgot to tell you to add:

        encoding="ASCII "

        to your xsl:output


        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.dt d">
        3: <html xmlns="http://www.w3.org/1999/xhtml">
        4: <body>
        5: <h2>My CD Collection</h2>
        6: <table border="1">
        7: <tr bgcolor="#9acd3 2">
        8: <th align="left">Ti tle</th>
        9: <th align="left">Ar tist</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
        "Greg" <gfaudet@enib.f r> wrote in message
        news:3f747e3d$0 $10420$626a54ce @news.free.fr.. .[color=blue]
        > "Dimitre Novatchev" <dnovatchev@yah oo.com> a écrit dans le message de[/color]
        news:[color=blue]
        > bl1t9h$6qf57$1@ ID-152440.news.uni-berlin.de...[color=green]
        > > Change:
        > >[color=darkred]
        > > > <html>[/color]
        > >
        > > to:
        > > <html xmlns="http://www.w3.org/1999/xhtml">
        > >
        > > but then you'll find other errors -- e.g. no "head" is present in the[/color]
        > output[color=green]
        > > of the transformation.[/color]
        >
        > Thanks, but after changing it, I still get the same error: "Fatal Error:[/color]
        No[color=blue]
        > DOCTYPE specified!".
        >[/color]
        http://validator.w3.org/check?uri=ht...Fcdcatalog.xml[color=blue]
        >
        > Like if the doctype-system/public won't work...?
        >
        > [SNIP]
        >
        >[/color]


        Comment

        • Greg

          #5
          Re: [XSLT] Valid XHTML

          > I forgot to tell you to add:[color=blue]
          >
          > encoding="ASCII "
          >
          > to your xsl:output[/color]

          Done.
          [color=blue]
          > Then I pass the result to the validater and get:[/color]

          [SNIP]
          [color=blue]
          > Below is the source input I used for this validation:[/color]

          [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?


          Comment

          • Dimitre Novatchev

            #6
            Re: [XSLT] Valid XHTML

            > Maybe that's the problem. I use my XML file directly, but you seem to use
            a[color=blue]
            > XHTML file resulting from my two files, or am I totally wrong.
            > Does the validator can validate XML files directly?[/color]

            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


            Comment

            Working...