I try to transform XHTML webpage using XSLT by extracting some of its parts. For example, I'd like to extract HEAD and BODY parts separately (it's only first step, next will be extracting some divs) and use them in my output XHTML document. Here is XSLT code:
<xsl:stylesheet version="2.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xhtml xsl xs">
<xsl:output
method="html"
omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes"/>
<xsl:template match="/">
<HTML>
<xsl:apply-templates/>
</HTML>
</xsl:template>
<xsl:template match="xhtml:HTML/xhtml:BODY">
<xsl:copy-of select="." disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="xhtml:HTML/xhtml:HEAD">
<xsl:copy-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
As an input XHTML I have www.wordpress.org/about source code (validating). As first neko purifier is fired (HTML->XHTML) and then my xslt transformation. When I take a look into output code everything looks similar:
Original code: codepad.org/5D7MCXSk
Code after transformation: http://codepad.org/fGzyAwF2
Except, when I open it in web browser I get "white wall" - nothing appears. I noticed that in source code of transformed site (both on chrome and firefox) syntax is highlighted up to the closing HEAD tag. It is very weird and I thing that it is causing the problem.
Any help will be very appreciated. Thanks in advance
xmlns="http://www.w3.org/1999/xhtml"which suggests you want to output XHTML element. Yourxsl:outputalso suggests you want to output an XHTML document. However XHTML is case-sensitive and all its elements and attributes are defined to be lower case so I don't understand then why you have a literal result element with nameHTML. So using lower-case element and attribute names for any result elements is a first step to have a meaningful XHTML result document generated by your transformation.match="xhtml:html/xhtml:head". If you still have problems then tell us two things, first of all whether you serve the transformation result as text/html or with an XML MIME type like application/xml or application/xml, and secondly, what result document you want to create from your input.