W3C home > Mailing lists > Public > www-html@w3.org > August 2003

Re: Using XML to create a compound element

From: Daniel Brockman <daniel@brockman.nu>
Date: Fri, 1 Aug 2003 22:22:31 +0200
Message-ID: <02ac01c3586a$a28aaa00$64b670d5@wigwam>
To: <mmuguira@cox.net>, <www-html@w3.org>

Hi Nicholas,

>   Sorry if I was unclear, let me show you the an example similar to the
pages I've been playing with, only a lot smaller.
>
> test.html:
> <?xml-stylesheet type="text/xml" href="./test.xsl">
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd" >
> <html xmlns="http://www.w3.org/1999/xhtml">
>   <myhead>
>     <script language="javascript" src="./someRandomScript.js" />
>   </myhead>
>   <body>
>     <h1>Playing with stylesheets</h1>
>   </body>
> </html>
>
> test.xsl:
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
>   <xsl:template match="myhead">
>       <head>
>        <title>Title</title>
>        <xsl:value-of select="myhead">
>       </head>
>   </xsl:template>
> </xsl:stylesheet>

Oh, well this clears everything up instantly. You want to perform a simple
transformation using XSLT! :-)

> And I would like to browser to display an html page with the <myhead> . .
. </myhead> transformed by the rules in the stylesheet. I've tried numerous
variations on this, and I can't help but feel that I'm missing some small
thing.

Indeed you are missing a small thing: You are placing your <myhead> element
in the XHTML namespace, but looking for it in the default namespace. The
best way to fix this is to place your element in a private namespace, such
as "mailto:mmuguira@cox.net," since that will isolate your element nicely
from the rest of the world. In markup:

    <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
        <myns:myhead xmlns:myns="mailto:mmuguira@cox.net">
            ...
        </myns:myhead>
        ...
    </xhtml:html>

And in the stylesheet:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:myns="mailto:mmuguira@cox.net">
        <xsl:template match="myns:myhead">
            ...
        </xsl:template>
    </xsl:stylesheet>


I hope this helps,

--
Daniel Brockman
daniel@brockman.nu
Received on Friday, 1 August 2003 16:24:41 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 23:40:10 UTC