need help to add a comment before <!DOCTYPE ... in xsl

Discussion in 'XML' started by jluo, Dec 20, 2007.

  1. jluo

    jluo Guest

    Hi all,

    Need some help here. I'm using these in a xsl:
    ~~~~~~~~~~~~~~~
    <?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="html"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-
    transitional.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/
    >


    <html>
    <head>

    After transform, the html output is:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>
    <head>
    ~~~~~~~~~
    I will need to add a comment before the <!DOCTYPE ... and would like
    the HTML output as:


    <!-- something as a comment must be added here -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    Can anyone please help? What can I do to create this comment? Can
    this be done on the client side (xslt, scripting...) or should it be
    done on the server side when Java code does the transform?

    Any help is really appreciated!

    Thanks in advance, Jane
    jluo, Dec 20, 2007
    #1
    1. Advertising

  2. jluo wrote:

    > I will need to add a comment before the <!DOCTYPE ... and would like
    > the HTML output as:
    >
    >
    > <!-- something as a comment must be added here -->
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    > www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    Create a comment like this:

    <xsl:template match="/">
    <xsl:comment>a comment</xsl:comment>
    <html xml:lang="en">
    <head>
    <title>a test</title>
    </head>
    <body>
    <h1>Example</h1>
    </body>
    </html>
    </xsl:template>

    That way it will occur before the root element. Whether it will occur
    before the DOCTYPE might be implementation dependent but a test here
    with Saxon 6 puts the comment before the DOCTYPE.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 20, 2007
    #2
    1. Advertising

  3. jluo

    jluo Guest

    Hi Martin,

    Thanks for the help. It did work after I comment out the xsl:eek:utput.
    It works great!

    A good day,
    Jane
    jluo, Dec 20, 2007
    #3
  4. jluo

    Guest

    On Dec 20, 12:14 pm, Martin Honnen <> wrote:
    > That way it will occur before the root element. Whether it will occur
    > before the DOCTYPE might be implementation dependent


    I believe it _is_ implementation dependent, at least in XSLT 1.0 where
    the doctype is not an explicit part of the XPath 1.0 data model.
    , Dec 21, 2007
    #4
  5. wrote:
    > On Dec 20, 12:14 pm, Martin Honnen <> wrote:
    >> That way it will occur before the root element. Whether it will occur
    >> before the DOCTYPE might be implementation dependent

    >
    > I believe it _is_ implementation dependent, at least in XSLT 1.0 where
    > the doctype is not an explicit part of the XPath 1.0 data model.


    I don't think looking at the data model helps: we are talking about the
    result of an XSLT 1.0 transformation where outputting a DOCTYPE
    declaration is only possible as part of the serialization. For output
    method="xml" the specification
    <URL:http://www.w3.org/TR/xslt#section-XML-Output-Method> says:
    "If the doctype-system attribute is specified, the xml output method
    should output a document type declaration immediately before the first
    element."
    That could be read as a requirement to serialize a comment added with
    xsl:comment outside of the root element before any DOCTYPE output by
    <xsl:eek:utput doctype-system="..."/>.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 21, 2007
    #5
  6. jluo

    Guest

    On Dec 21, 12:24 pm, Martin Honnen <> wrote:
    > "If the doctype-system attribute is specified, the xml output method
    > should output a document type declaration immediately before the first
    > element."
    > That could be read as a requirement to serialize a comment added with
    > xsl:comment outside of the root element before any DOCTYPE output by
    > <xsl:eek:utput doctype-system="..."/>.


    I agree it could be read that way. I'm not sure this was the intent,
    nor how many implementations actually exhibit that exact behavior...
    I'd also note that in the spec there's an important distinction in
    most W3C specs between SHOULD and MUST, and that the use of the former
    would at most mean this is recommended-but-not-required behavior.
    , Dec 23, 2007
    #6
    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. Alec S.
    Replies:
    10
    Views:
    10,083
    Alec S.
    Apr 16, 2005
  2. Ken Larson
    Replies:
    1
    Views:
    581
    Philippe Poulard
    Feb 17, 2004
  3. Tjerk Wolterink

    XSL Doctype with entities

    Tjerk Wolterink, Nov 20, 2004, in forum: XML
    Replies:
    3
    Views:
    727
    Martin Honnen
    Nov 21, 2004
  4. Replies:
    1
    Views:
    3,583
    A. Bolmarcich
    May 27, 2005
  5. Larry Lindstrom
    Replies:
    19
    Views:
    1,268
    Jonathan N. Little
    Jun 12, 2012
Loading...

Share This Page