XSLT HTML Validation

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

    XSLT HTML Validation

    I am producing HTML from XslTransform (C#) and the HTML does not
    validate, see http://www.redburg.co.uk/mira/mira415_ev_wh_ch.html as
    an example.

    I am using the following XSLT code:

    <?xml version="1.0"?>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" version="4.01"/>
    <xsl:output doctype-system="http://www.w3.org/TR/html4/strict.dtd" />
    <xsl:output doctype-public="-//W3C//DTD HTML 4.01//EN"/>

    Are there any URL's giving more details on xsl and html and how the
    HTML can validate after being created from XslTransform.
  • Oleg Tkachenko [MVP]

    #2
    Re: XSLT HTML Validation

    Trevor Oakley wrote:
    [color=blue]
    > I am producing HTML from XslTransform (C#) and the HTML does not
    > validate, see http://www.redburg.co.uk/mira/mira415_ev_wh_ch.html as
    > an example.[/color]

    What do you mean "does not validate" ? Basically in XSLT resulting
    document never gets validated, it's stylesheet author's responsibility
    to output valid result.

    --
    Oleg Tkachenko [XML MVP]

    Comment

    • Trevor Oakley

      #3
      Re: XSLT HTML Validation


      I am referring to W3C validation of HTML. My output from the XML/XSLT is
      HTML but the doctype is absent which causes a failed validation.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Oleg Tkachenko [MVP]

        #4
        Re: XSLT HTML Validation

        Trevor Oakley wrote:
        [color=blue]
        > I am referring to W3C validation of HTML. My output from the XML/XSLT is
        > HTML but the doctype is absent which causes a failed validation.[/color]

        Aha. Most likely the problem has something to do with how you run the
        transformation in your C# code. Make sure you don't transform to
        XmlWriter or XmlReader, because as stated at MSDN, xsl:output
        instruction is ignored in such case.

        --
        Oleg Tkachenko [XML MVP]

        Comment

        • Trevor Oakley

          #5
          Re: XSLT HTML Validation

          My code is below. The error appears to originate from a failure to
          detect encoding data by the HTML validator and it "assumes" UTF8 and
          also any doctype data. I need UTF8 encoding to get the "£" working.


          thisStream.Posi tion = 0;
          string xslPath = Server.MapPath( "XSLName.xs l");
          string htmlPath = Server.MapPath( HTMLName);

          XPathDocument aXPathDocument = new XPathDocument(t hisStream);
          XslTransform transform = new XslTransform();

          transform.Load( xslPath, resolver);
          XmlTextWriter aWriter = new XmlTextWriter(h tmlPath, Encoding.UTF8);

          aWriter.Formatt ing = Formatting.Inde nted;
          aWriter.Indenta tion=4;
          transform.Trans form(aXPathDocu ment,null,aWrit er, resolver);
          aWriter.Flush() ;
          aWriter.Close() ;




          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Oleg Tkachenko [MVP]

            #6
            Re: XSLT HTML Validation

            Trevor Oakley wrote:
            [color=blue]
            > My code is below. The error appears to originate from a failure to
            > detect encoding data by the HTML validator and it "assumes" UTF8 and
            > also any doctype data. I need UTF8 encoding to get the "£" working.[/color]

            I wrote to you in prev mail:

            Make sure you don't transform to XmlWriter or XmlReader, because as
            stated at MSDN, xsl:output instruction is ignored in such case.

            --
            Oleg Tkachenko [XML MVP]

            Comment

            • Trevor Oakley

              #7
              Re: XSLT HTML Validation

              My transform is using XmlTextWriter not XmlWriter.



              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Yan Leshinsky

                #8
                Re: XSLT HTML Validation

                use StreamWriter instead:
                StreamWriter aWriter = new StreamWriter(ht mlPath)
                transform.Trans form(aXPathDocu ment,null,aWrit er, resolver);

                "Trevor Oakley" <sales@trevoroa kley.com> wrote in message
                news:eEW5HwCPEH A.2088@TK2MSFTN GP10.phx.gbl...[color=blue]
                > My transform is using XmlTextWriter not XmlWriter.
                >
                >
                >
                > *** Sent via Developersdex http://www.developersdex.com ***
                > Don't just participate in USENET...get rewarded for it![/color]


                Comment

                • Trevor Oakley

                  #9
                  Re: XSLT HTML Validation

                  I had already got it working with StreamWriter, but my implementation
                  wrote the XslTransform to a MemoryStream and then to a file via
                  StreamWriter.



                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  • Oleg Tkachenko [MVP]

                    #10
                    Re: XSLT HTML Validation

                    Trevor Oakley wrote:
                    [color=blue]
                    > My transform is using XmlTextWriter not XmlWriter.[/color]

                    Hehe, XmlTextWriter is an implementation of XmlWriter.
                    Use StreamWriter instead.

                    --
                    Oleg Tkachenko [XML MVP]

                    Comment

                    • Oleg Tkachenko [MVP]

                      #11
                      Re: XSLT HTML Validation

                      Trevor Oakley wrote:
                      [color=blue]
                      > I had already got it working with StreamWriter, but my implementation
                      > wrote the XslTransform to a MemoryStream and then to a file via
                      > StreamWriter.[/color]

                      Why not directly to a file? That's pure waste of memory to have interim
                      MemoryStream here.

                      --
                      Oleg Tkachenko [XML MVP]

                      Comment

                      • Trevor Oakley

                        #12
                        Re: XSLT HTML Validation

                        I assume XmlTextWriter has different methods and properties so it does
                        not follow that if XmlWriter fails to use xsl:output tags then
                        XmlTextWriter will also.




                        *** Sent via Developersdex http://www.developersdex.com ***
                        Don't just participate in USENET...get rewarded for it!

                        Comment

                        • Oleg Tkachenko [MVP]

                          #13
                          Re: XSLT HTML Validation

                          Trevor Oakley wrote:
                          [color=blue]
                          > I assume XmlTextWriter has different methods and properties so it does
                          > not follow that if XmlWriter fails to use xsl:output tags then
                          > XmlTextWriter will also.[/color]

                          XmlWriter is abstract class. XmlTextWriter is one of implementations .
                          xsl:output instruction is ignored by design, when transformation is done
                          to any XmlWriter implementation.
                          You should also realize that you never output HTML when transforming to
                          any XmlWriter, because XmlWriter writes well-formed XML by definition
                          and by design.
                          --
                          Oleg Tkachenko [XML MVP]

                          Comment

                          Working...