kg1794
09-01-2009, 01:21 PM
Hi there,
I'm using PHP to output the contents of an XML file, which is styled using XSL.
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('includes/xmlconversion.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// transform the XML into HTML using the XSL file
if ($html = $xp->transformToXML($scrap)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
} // if
Before the code starts outputting the contents of the XML file, it inserts the following into the XHTML document, which causes it to fail validation because the DOCTYPE has already been declared at the head of the document:
<!DOCTYPE h2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The XSL code I use is this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:output method="xml" indent="yes"
omit-xml-declaration="yes"
media-type="application/xhtml+xml"
encoding="iso-8859-1"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title">
<h2><xsl:apply-templates/></h2>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
</xsl:stylesheet>
What's curious is the DOCTYPE h2 PUBLIC part, it seems to be taking the h2 from the "title" template match. Why is this? How do I stop XSL outputting a DOCTYPE?
Many thanks for any help.
I'm using PHP to output the contents of an XML file, which is styled using XSL.
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('includes/xmlconversion.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// transform the XML into HTML using the XSL file
if ($html = $xp->transformToXML($scrap)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
} // if
Before the code starts outputting the contents of the XML file, it inserts the following into the XHTML document, which causes it to fail validation because the DOCTYPE has already been declared at the head of the document:
<!DOCTYPE h2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The XSL code I use is this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:output method="xml" indent="yes"
omit-xml-declaration="yes"
media-type="application/xhtml+xml"
encoding="iso-8859-1"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title">
<h2><xsl:apply-templates/></h2>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
</xsl:stylesheet>
What's curious is the DOCTYPE h2 PUBLIC part, it seems to be taking the h2 from the "title" template match. Why is this? How do I stop XSL outputting a DOCTYPE?
Many thanks for any help.