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

Re: Namespaces best practice in XML

Subject: Re: Namespaces best practice in XML
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 4 Apr 2006 14:43:40 +0100
xhtml namespace xsl
On 4/4/06, tom tom <tomxsllist@xxxxxxxxxxx> wrote:
> My XML Source has a default namespace and never uses prefixes. I am writing
> a stylesheet which  transforms this into XHTML. In the XSLT I (ideally)
> never want to prefix any XHTML output elements or any source XML element
> references.

You will have to do one or the other, as there is only one default
namespace, unless you use two passes with the second pass to put all
the output elements in the xhtml namespace.

eg:

Store the first pass in a variable:

<xsl:variable name="first_pass">
  <xsl:apply-templates/>
</xsl:variable>

Use an identity template put all the elements in the xhtml namespace:

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

Generate your output by applying the identity template to the first pass:

<xsl:template match="/">
  <xsl:for-each select="$first_pass">
    <xsl:apply-templates mode="xhtml"/>
  </xsl:for-each>
</xsl:template>


cheers
andrew

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.