xsl-list
[Top] [All Lists]

Re: [xsl] Outputting Doctype

2006-03-16 03:45:08
On 3/16/06, Aaron Johnson <Aaron2(_dot_)Johnson(_at_)uwe(_dot_)ac(_dot_)uk> 
wrote:
I want to add a doc type to my xsl so that the final html output will be
xhtml compliant.

I am passing in the doctype [ escaped ] as aparameter...

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; /&gt;

...and then applying a template...

<xsl:template name="doctype">
     <xsl:value-of select="$doctype"/>
</xsl:template>

But getting this result in the output:

&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; /&amp;gt;

Is there a correct way to implement a doctype for output?

Hi Aaron,

I hope UWE is treating you well...

To output a doctype, use xsl:output:

<xsl:output method="xhtml" encoding="US-ASCII"
  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>


If you are using a schema aware processor, such as Saxon SA, you can
validate your output as its being generated, which is great.  To do
this, add the schema definition you want to validate against:

<xsl:import-schema namespace="http://www.w3.org/1999/xhtml";
 schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd"/>

...and then tell the processor which part to validate - in the case of
XHTML output its the whole document, so I wrap the output in a
result-document with validation set to strict:

<xsl:template match="/">
  <xsl:result-document validation="strict">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:template>

Now if any of your output fails to conform to the XHTML transitional
schema, it will tell which template generated the bad code.

Previously I thought only the transitional XSD was available, but it
seens there is also an XHTML strict schema available from
http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd but I haven't used
this one yet, so I can't comment on whether its complete.  Has anyone
else used the stict XHTML schema?

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>