[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can I change the namespace of elements included vi

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

  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.