XHTML with Namespaces -> HTML 4.0 Loose

Subject: XHTML with Namespaces -> HTML 4.0 Loose
From: Brian Dupras <briand@xxxxxxxxxxx>
Date: Thu, 16 Mar 2000 17:04:52 -0700
I have an interesting dilema - I need to convert a bunch of Data, Text, and
XHTML (with namespaces) into HTML4.  The spin is that the Data may contain
user-input html elements that my system treats as opaque.  For instance, I
give the user a form to enter text.  

If they type in "This is a sample.", then I generate  <html:p>This is a
sample.</html:p>  by using DOM and addTextNode().


If they type in "This is an <b>HTML</b> sample.", then I generate
<html:p>This is an &lt;b>HTML&lt;b> sample.</html:p> by using the same DOM
addTextNode().


What I need to do is pull that same XML out of storage and spit out to the
browser, "<p>This is an <b>HTML</b> sample.</p>" using XSLT if I can.


There are two things here.  First, I need to be sure that my own <html:*>
elements get translated to valid HTML 4 (singular <br> tags from <html:br/>,
for example).  Also, I need to pass through the user's input text, including
and valid or broken HTML tags that they typed in.


The XSLT doc I wrote to do that is presently not working properly.  It is
included below.  I'm sure this is just a matter of getting the
output-method, output escaping, text formatting, etc all set up properly.  I
could use some pointers here, though.



By specifying that the output-method is "html", I should get some singular
tags like <br>.  But, in my output from below, I'm still getting <br/>.  I
think this might have to do with creating the elements from scratch useing
<xsl:element>.

If I pass in the above html example, the xslt below spits out "This is an
&lt;b>HTML&lt;b> example.", which obviously causes the <b> tag to render to
the page instead of bolding the text.


Thanks for any advice.

Brian Dupras
Centera Information Systems, Inc.
phone 303.381.4420 (direct)
phone 303.939.0200 (operator)
fax	303.939.0111
web	http://www.centera.com
email	briand@xxxxxxxxxxx



My broken XHTML -> HTML xslt:

<?xml version="1.0"?>

<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" 
		indent="yes"
		omit-xml-declaration="yes" 
		/>
	
<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="html:*">
	<xsl:element name="{substring-after(name(.),':')}">
		<xsl:for-each select="@*">
			<xsl:attribute name="{name(.)}"><xsl:value-of
select="."/></xsl:attribute>
		</xsl:for-each>
		<xsl:apply-templates/>
	</xsl:element>
</xsl:template>


</xsl:stylesheet>


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


Current Thread