Ustaw DOCTYPE HTML5 za pomocą XSLT

Jak mamczysto ustawić doctype pliku NA HTML5 <!DOCTYPE html> poprzez XSLT (w tym przypadku z zbiorczym.xdv )

Poniżej, który jest najlepszy, jaki udało mi się znaleźć w Google foo:

<xsl:output
    method="html"
    doctype-public="XSLT-compat"
    omit-xml-declaration="yes"
    encoding="UTF-8"
    indent="yes" />

Produkuje:

<!DOCTYPE html PUBLIC "XSLT-compat" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Author: Paul Sweatte, 2010-08-02

12 answers

Myślę, że jest to obecnie obsługiwane tylko przez zapisywanie doctype jako tekst:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="utf-8" indent="yes" />

  <xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
    <html>
    </html>
  </xsl:template>

</xsl:stylesheet>

Spowoduje to następujące Wyjście:

<!DOCTYPE html>
<html>
</html>
 150
Author: Dirk Vollmar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-09 00:07:40

Aby użyć prostego HTML doctype <!DOCTYPE html>, musisz użyć disable-output-escaping feature: <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>. Jednak disable-output-escaping jest opcjonalną funkcją W XSLT, więc twój silnik XSLT lub rurociąg serializacji mogą go nie obsługiwać.

Z tego powodu HTML5 zapewnia alternatywny doctype dla kompatybilności z HTML5-nieświadomymi wersjami XSLT (tj. wszystkimi obecnie istniejącymi wersjami XSLT) i innymi systemami, które mają ten sam problem. Alternatywnym typem doctype jest <!DOCTYPE html SYSTEM "about:legacy-compat">. Aby wypisać ten typ dokumentu, użyj atrybut doctype-system="about:legacy-compat" na elemencie xsl:output bez używania atrybutu doctype-public w ogóle.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html" doctype-system="about:legacy-compat"/>
   ...
   <html>
   </html>
</xsl:stylesheet>
 66
Author: hsivonen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-05 14:51:33
<xsl:output
     method="html"
     doctype-system="about:legacy-compat"
     encoding="UTF-8"
     indent="yes" />

To wyjście

<!DOCTYPE html SYSTEM "about:legacy-compat">

To jest zmodyfikowane jako moja poprawka do http://ukchill.com/technology/generating-html5-using-xslt/

 30
Author: Jim Michaels,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-06 07:24:10

Z Saxon 9.4 możesz użyć:

<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes" />

To generuje:

<!DOCTYPE HTML>
 20
Author: stephanme,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-15 10:54:26

Użyj doctype-system zamiast doctype-public

 10
Author: Jirka Kosek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-02 12:01:55

You must use XHTML 1.0 Strict as the doctype jeśli chcesz, aby wyjście XHTML było zgodne z HTML5, serializer XML libxml2 ma specjalny tryb wyjścia wyzwalany przez doctypy XHTML 1.0, który zapewnia, że wyjście jest zgodne z XHTML, (np. <br /> zamiast <br/>, <div></div> zamiast <div/>). doctype-system="about:legacy-compat" czy nie uruchamia ten tryb zgodności

Jeśli jesteś zadowolony z wyjścia html, ustawienie <xsl:output method="html"> powinno zrobić właściwą rzecz. Następnie możesz ustawić doctype za pomocą <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>, jednak będzie to wymagało instalacji w odpowiednim miejscu, ponieważ XDV jeszcze tego nie obsługuje.

W rzeczywistości wydaje się, że <xsl:output method="html"/> również nie pomaga - spowoduje to, że <br/> będzie wyświetlane jako <br></br>.

 10
Author: Laurence Rowe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-07 20:13:33

Ta odmiana porad Jirki Kosek , via Advanced XDV theming on Plone.org wydaje mi się, że pracuje dla mnie w kolektywie.xdv .

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output
      doctype-public="HTML"
      doctype-system=""/>
</xsl:stylesheet>
 6
Author: Jon Hadley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:03:04

To jest komentarz, ale nie mam wystarczającej ilości punktów karmy, aby umieścić go we właściwym miejscu. Westchnienie.

Doceniam, że jest to prawdopodobnie poprawny, oparty na standardach sposób na osiągnięcie tego ,czego chcę (podałem go jako taki). Ale pierwszy nie jest obsługiwany (mój procesor się przewraca) , a drugi nadal powoduje " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " w moim doctype. Jak zasugerował @Jirka Kosek, myślę, że mój procesor XSLT może być złamana.

Nie, twój procesor XSLT nie jest zepsuty, po prostu XDV dodaje:

<xsl:output method="xml" indent="no" omit-xml-declaration="yes" media-type="text/html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

Domyślnie, więc po dodaniu drugiego <xsl:output doctype-system="about:legacy-compat"/> poprzedni doctype-public nie jest nadpisywany.

Zauważ, że XHTML 1.0 strict jest wymieniony jako przestarzały dozwolony ciąg doctype , więc jest całkowicie dopuszczalne używanie tego doctype i nadal nazywanie go HTML5.

 5
Author: Laurence Rowe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-04 14:18:20

Przepraszam, że podaję tylko linki, ale to było omawiane w grupie WHATWG, ale minęło wiele miesięcy, odkąd się z tym uporałem. Tutaj Ian Hickson i niektórzy eksperci XML omawiają this:
http://lists.w3.org/Archives/Public/public-html/2009Jan/0640.html
http://markmail.org/message/64aykbbsfzlbidzl
a oto faktyczny Numer wydania:
http://www.w3.org/html/wg/tracker/issues/54
a oto to dyskusja
http://www.contentwithstyle.co.uk/content/xslt-and-html-5-problems

 3
Author: Rob,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-02 15:38:53

Użyj tego znacznika

<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="XSLT-compat" indent="yes"/>
 2
Author: Anil Kumar Gupta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-12 09:40:27

Poniższy kod będzie działał jako samodzielny szablon, jeśli zostanie zapisany jako html5.xml:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="html5.xml"?>
<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
            >
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />

<xsl:template match="xsl:stylesheet">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="/">
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    <body>
      <xsl:text>hi</xsl:text>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Referencje

 1
Author: Paul Sweatte,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-02 16:26:18

Tego używam do generowania zgodnego HTML5 doctype (wyprowadzanie HTML5, inaczej robienie rzeczy legacy)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/TR/REC-html40">

    <xsl:output
        method="html"
        version="5.0"
        doctype-system="about:legacy-compat"
        encoding="UTF-8"
        indent="yes" />
 1
Author: BananaAcid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-16 00:46:55