Re: XHTML to HTML 4

Subject: Re: XHTML to HTML 4
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Thu, 06 Apr 2000 18:35:28 +0200
The nasty part of the transformation is the &lt;p&gt; which is adding
nodes in the middle of a text...

Otherwise, it's a matter of transforming the namespaces and letting the
html output method do the trick...

There maybe simpler solutions, but something like :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
  xmlns:html='http://www.w3.org/1999/xhtml'
  exclude-result-prefixes = "html">
<xsl:output method="html"
	doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>

<xsl:template match="*">
	<xsl:element name="{local-name(.)}">
		<xsl:apply-templates select="@*|node()"/>
	</xsl:element>
</xsl:template>

<xsl:template match="@*">
	<xsl:attribute name="{local-name(.)}">
		<xsl:value-of select="."/>
	</xsl:attribute>
</xsl:template>

</xsl:stylesheet>

would be sufficient (and you can add templates if you want to have a
specific behavior for a specific HTML tag).

To include your <p>, you'd need to add a template like

<xsl:template match="text()" name="text">
        <xsl:param name="text" select="."/>
        <xsl:choose>
        <xsl:when test='contains($text, "&lt;p&gt;")'>
	   <xsl:value-of select='substring-before($text, "&lt;p&gt;")'/>
           <p/>
           <xsl:call-template name="text">
             <xsl:with-param name="text" select='substring-after($text,
"&lt;p&gt;")'/>
           </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="$text"/>
        </xsl:otherwise>
        </xsl:choose>
</xsl:template>

Hope this helps.

Eric

-- 
------------------------------------------------------------------------
Eric van der Vlist       Dyomedea                    http://dyomedea.com
creator                  http://xmlfr.org            http://ducotede.com
editor                   http://xmlhack.com              http://dmoz.org
------------------------------------------------------------------------


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread