DOCTYPE declaration getting lost when using XSL
Asked Answered
I

2

8

The input to my XSL is an XHTML. After applying the XSL the DOCTYPE declaration that was present in the input XHTML gets lost in the output. Do i have an option to copy/retain the DOCTYPE declaration in the output using XSL. The XSL processor that i am using is SAXON.

Interlocutress answered 20/4, 2010 at 14:59 Comment(1)
I would gladly upvote an answer to do it automatically in xslt-1.0.Bolero
P
13

Add an output directive:

<xsl:output 
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>

By the way, output directives stack - you can have as many of them as you want.

Paulus answered 20/4, 2010 at 16:25 Comment(7)
If the input xhtml had the DOCTYPE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> If i have set the DOCTYPE as shown above then I will end up setting the DOCTYPE of the output as <!DOCTYPE html PUBLIC "="-//W3C//DTD XHTML 1.0 Strict//EN" "w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Is there a way to get the DOCTYPE of the input to the output?Interlocutress
@Rachel: Hm… not easy. I'm not aware of a way to do this in XSLT 1.0. What XSLT version do you use? This page indicates there is a way to do it in XSLT 2.0: biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/…Paulus
I use XSL 2.0. Will check the link.Interlocutress
Can i get the 2 info doctype public and doctype system as input params and set them in output dynamically as shown below? <xsl:param name="doctype.public" as="xsd:string" /> <xsl:param name="doctype.system" as="xsd:string" /> <xsl:output doctype-public="$doctype.public" doctype-system="$doctype.system" /> I am getting the output as: <!DOCTYPE html PUBLIC "$doctype.public" "$doctype.system"> I am getting the variable name in the output as shown above. Am i missing something?Interlocutress
@Rachel: Yes you are missing something, namely the curly braces that trigger variable evaluation: <xsl:output doctype-public="{$doctype.public}" doctype-system="{$doctype.system}" />Paulus
I tried it and got the error, XTSE0020: Invalid character in doctype-public parameter where i passed "-//W3C//DTD XHTML 1.0 Transitional//EN" for public. I just tried adding only doctype system using, <xsl:output doctype-system="{$doctype.system}" /> Output: <!DOCTYPE html SYSTEM "{$doctype.system}"> Same issue.Interlocutress
@Rachel: Go back to the document I linked, and have a closer look: They've used <xsl:result-document>, not <xsl:output> (I was convinced that this would not work with <xsl:output> anyway, but I was unsure if XSLT 2.0 maybe allowed it).Paulus
H
2

I solve this problem, as I describe that here:

https://mcmap.net/q/1325286/-setting-xsl-doctype

<xsl:text disable-output-escaping='yes' >&#x3c;!DOCTYPE html&#x3e;&#xA;</xsl:text>
Hilde answered 29/6, 2023 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.