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

Re: Namespaces and the identity transform

Subject: Re: Namespaces and the identity transform
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 29 Oct 2002 18:19:27 +0000
Re:  Namespaces and the identity transform
Hi James,

> How can I design an identity transform that applies the default
> namespace to the output? I prefer not to have to restructure my
> input, and I want all output nodes to use the strict xhtml
> namespace. I substituted the above identity transform with the
> following and this seems to produce the correct output, but is this
> the most efficient way of doing it?
>
> <xsl:template match="*">
>         <xsl:element name="{name()}">
>                 <xsl:apply-templates select="@*|node()"/>
>         </xsl:element>
> </xsl:template>
>
> <xsl:template match="@*">
>         <xsl:attribute name="{name()}">
>                 <xsl:value-of select="."/>
>         </xsl:attribute>
> </xsl:template>

If this is the only processing that you're doing, you don't have to
worry about having a separate template for the attributes; you can
just do:

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>

Note that I've used local-name() rather than name(); that's just in
case someone includes a prefix on the elements in your source
document.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.