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.
+1
A:
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.
Tomalak
2010-04-20 16:25:06
If the input xhtml had the DOCTYPE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Is there a way to get the DOCTYPE of the input to the output?
Rachel
2010-04-20 16:40:12
@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: http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200807/msg00398.html
Tomalak
2010-04-20 17:01:13
I use XSL 2.0. Will check the link.
Rachel
2010-04-20 18:44:20
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?
Rachel
2010-04-21 15:04:16
@Rachel: Yes you are missing something, namely the curly braces that trigger variable evaluation: `<xsl:output doctype-public="{$doctype.public}" doctype-system="{$doctype.system}" />`
Tomalak
2010-04-21 15:06:29
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.
Rachel
2010-04-21 15:56:56
@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).
Tomalak
2010-04-21 16:12:51