bug in XSLT
Friday, 23 February 2018 · 3 messages · last reply 24 Feb 2018
ND
nikos dimitrakas23 Feb 2018 10:31 #
There seems to be a problem when using baseX to create html with XSLT. Saxon seems to add a META-tag if the head-tag is present. But it is not <meta/>. It is instead <meta> (without closing tag, which is ok in html) and this causes baseX to give an error:
The element type "META" must be terminated by the matching end-tag "</META>". With the newer version of Saxon the error is the same but the case has been changed to <meta> instead of <META>.
This can be easily reproduced with the following query:
let $s :=
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head/><body/></html>
</xsl:template>
</xsl:transform>
return xslt:transform(/, $s)In the new XSLT version there is an option to set the output to xhtml and that works, but the html output (which is the only available option in XSLT 1) fails. The generated meta tag seem to be this
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">I have even tried to override this by specifying that meta tag myself with closing tag but that does not work.
I even tried setting the attribute include-content-type in the xsl:output, but it had no effect.
Setting the output method to xml would work if the html genererated is in fact correct xml (like in the example above).
Output metod "text" seems to also behave strangely. Maybe BaseX ignores the output method and tries to treat everything as xml?
/nikos
KK
Kristian Kankainen23 Feb 2018 10:54 #
You could use the html module to convert the html into xml. Read about the html module here: http://docs.basex.org/wiki/HTML_Module
Br
Kristian K
23. veebr 2018 11:31 AM kirjutas kuupäeval nikos dimitrakas <nikos at dsv.su.se>:
Quoted text · nikos dimitrakas · 57 lines
> There seems to be a problem when using baseX to > create html with XSLT. Saxon seems to add a META-tag if the head-tag is > present. But it is not <meta/>. It is instead <meta> (without > closing tag, which is ok in html) and this causes baseX to give an > error: > > The element type "META" must be terminated by the matching > end-tag "</META>". With the newer version of Saxon the > error is the same but the case has been changed to <meta> instead > of <META>. > > > This can be easily reproduced with the following query: > > > let $s := > > <xsl:transform version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="html"/> > > <xsl:template match="/"> > > > <html><head/><body/></html> > > </xsl:template> > > </xsl:transform> > > return xslt:transform(/, $s) > > > In the new XSLT version there is an option to set the output to xhtml and > that works, but the html output (which is the only available option in > XSLT 1) fails. The generated meta tag seem to be this > > > <meta http-equiv="Content-Type" content="text/html; > charset=UTF-8"> > > > I have even tried to override this by specifying that meta tag myself > with closing tag but that does not work. > > I even tried setting the attribute include-content-type in the > xsl:output, but it had no effect. > > Setting the output method to xml would work if the html genererated is in > fact correct xml (like in the example above). > > Output metod "text" seems to also behave strangely. Maybe BaseX > ignores the output method and tries to treat everything as xml? > > > /nikos
AB
Andy Bunce24 Feb 2018 22:45 #
Your stylesheet returns html. The html serialization adds the meta tag without a closing tag.
xslt:transform must return node() so fails trying to extract XML from that.
Maybe xslt:transform-text[1] can help, changing your last line toreturn xslt:transform-text(/, $s)
Gives
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body></body>
</html>Quoted text · Kristian Kankainen · 48 lines
On 23 February 2018 at 09:54, Kristian Kankainen <kristian at keeleleek.ee> wrote: > You could use the html module to convert the html into xml. Read about the > html module here: http://docs.basex.org/wiki/HTML_Module > > Br > Kristian K > 23. veebr 2018 11:31 AM kirjutas kuupäeval nikos dimitrakas < > nikos at dsv.su.se>: > > There seems to be a problem when using baseX to create html with XSLT. > Saxon seems to add a META-tag if the head-tag is present. But it is not > <meta/>. It is instead <meta> (without closing tag, which is ok in html) > and this causes baseX to give an error: > The element type "META" must be terminated by the matching end-tag > "</META>". With the newer version of Saxon the error is the same but the > case has been changed to <meta> instead of <META>. > > This can be easily reproduced with the following query: > > let $s := > <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/ > 1999/XSL/Transform"> > <xsl:output method="html"/> > <xsl:template match="/"> > <html><head/><body/></html> > </xsl:template> > </xsl:transform> > return xslt:transform(/, $s) > > In the new XSLT version there is an option to set the output to xhtml and > that works, but the html output (which is the only available option in XSLT > 1) fails. The generated meta tag seem to be this > > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> > > I have even tried to override this by specifying that meta tag myself with > closing tag but that does not work. > I even tried setting the attribute include-content-type in the xsl:output, > but it had no effect. > Setting the output method to xml would work if the html genererated is in > fact correct xml (like in the example above). > Output metod "text" seems to also behave strangely. Maybe BaseX ignores > the output method and tries to treat everything as xml? > > /nikos > >
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery