Re: [xsl] Can I change the namespace of elements included via document()?

Subject: Re: [xsl] Can I change the namespace of elements included via document()?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 2 Jun 2003 16:58:26 +0100

  Is there any way to bring the selected <entity> tag into the "html"
  namespace "on the fly", so that the existing "html:p" templates will work,
  without having to have that rather (to me) ugly
  xmlns="http://www.w3.org/1999/xhtml"; attribute on the <entities> element in
  reusable.xml?


Note to Xpath/XSLT xmlns is _not_ an attribute it is just part of the
syntax for the name of an element.

You can of course have templates that change p in no-namespace to
p in the xhtml namespace, but to XSLT this is the same as changing p to
q and you code it the same way

to change p to q you'd do

<xsl:template match="p">
  <q>
   <xsl:copy-of select="@*/>
    <xsl:apply-templates/>
   ...

so you could do:

<xsl:template match="p">
  <html:p>
   <xsl:copy-of select="@*/>
    <xsl:apply-templates/>
   ...

You can do them all at once by:


<xsl:template match="*">
  <xsl:element name="{local-name()}" namespace="xmlns="http://www.w3.org/1999/xhtml";>
   <xsl:copy-of select="@*/>
    <xsl:apply-templates/>
  </xsl:element>




Note that it is politically incorrect to go

<entities xmlns="http://www.w3.org/1999/xhtml";>
		<entity id="some_id">
			<p>S

You ought really go

<entities>
		<entity id="some_id">
			<p xmlns="http://www.w3.org/1999/xhtml";>S

As the whole point of namespaces is that element names have a globally
unique name indicating where they come from, and that <entities> element
does _not_ come from XHTML so you shouldn't really put it in the XHTML
namespace. XSLT of course will process it correctly irrespective of
politics though.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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


Current Thread