Hi George,

Your query will probably give a better result if you wrap head and
body into an html element:

  let $head := <head></head>
  let $body := <body></body>
  return serialize(
    element html { $head, $body },
    map { "method": "html", "version": "5.0"}
  )

But you are right, in general it makes no sense to output the document
type declaration more than once. The nifty details are defined in a
separate specification [1], The document is very comprehensive, but
there are still some combinations of serialization parameters that are
not discussed in full depth. I noticed that BaseX and Saxon behave
differently in some cases. For example, Saxon may raise SEPM0004 error
for both the "xml" and "xhtml" output method, while it’s only defined
for "xml" in the spec. This error code is raised if a doctype
declaration is requested, and if more than one item is to be output.

BaseX followed the spec more closely, but as the Saxon solution seems
more consistent to me, I just updated our code:
• The new snapshot [2] will output only one doctype declaration.
• SEPM0004 will also be raised for the xhtml method now (not for html,
though, because html serialization is generally more lax than
xml/xhtml serialization).
• In analogy with Saxon, I turned the implementation-defined default
for the "include-content-type" parameter to "yes"; so the output of
the query above will now be as follows:

  <!DOCTYPE html>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
    </head>
    <body></body>
  </html>

Cheers,
Christian

[1] https://www.w3.org/TR/xslt-xquery-serialization-31/
[2] http://files.basex.org/releases/latest/


> This is probably a non issue, but I thought I should report it anyway. I was 
> playing around with serialization options today and I noticed that:
>
> let $head := <head></head>
> let $body := <body></body>
> return serialize(($head, $body), map { "method": "html", "version": "5.0"})
>
> will return
>
> <!DOCTYPE html>
> <head></head>
> <!DOCTYPE html>
> <body></body>
>
> I don't think fn:serialize() is defined in the xquery spec so it's 
> implementation specific so I guess it also could be correct :)
>
> Also I have a question, I remember in the past a discussion about need for 
> extra testing (XQuery spec wise) in BaseX? Is this still an issue? Hopefully 
> I can find some time and help out with that.
>
> Regards,
>
> George

Reply via email to