Re: transform XHTML to HTML -- namespace problem?

K.M. Ku wrote:
> 
> Dear ALL,
> 
> I am a newbie..
> I got a problem w/ xslt . The problem seems to be the namespace issue of the
> source XHTML file. 
> 
> Here are my steps:
> 
> 1) I use tidy to tidy up a html page into xhtml file . 
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta name="generator" content="HTML Tidy, see www.w3.org" />
> <meta name="ROBOTS" content="NOARCHIVE" />

Here every non-prefixed element is in the XHTML namespace.

> 2) I write a simple stylesheet to extract all td elements.
> 
> <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xsl:version="1.0">
> <head>
> <title>aa</title>
> </head>
> 
> <body>
> 
> <xsl:for-each select="//td">
>   <p>qq</p>
> </xsl:for-each>
> </body>
> </html>

Here you try to match element from the null (not XHTML) namespace.

> 3) I use Xalan - Java to convert the file. 
> 
> However, the transformation gives nothing, and it seems that it never sees
> the td nodes.

Right.

> 4) I removed all the XHTML declaration of the source XHTML file so that it
> changed to:
> 
> <html>
> <head>
> <meta name="generator" content="HTML Tidy, see www.w3.org" />
> <meta name="ROBOTS" content="NOARCHIVE" />

Now the elements are in a null namespace

> And it works now...

because they are matched by your XSLT.

> I know I did something wrong.

* Define a prefix in your XSLT for XHTML
   (xmlns:x="http://www.w3.org/1999/xhtml").
* Use this prefix when matching and selecting elements (match="x:td").
-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                             (Te Deum, 4th cent.)

Received on Thursday, 29 January 2004 04:35:32 UTC