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

Re: default or no namespace

Subject: Re: default or no namespace
From: Piet van Oostrum <piet@xxxxxxxxxxxxxx>
Date: Tue, 28 Dec 2010 10:40:00 -0400
Re:  default or no namespace
ac wrote:

 > Hi,
 > 
 > With XSLT2, I have an element that can be either in no namespace or
 > in the default namespace, based on some condition, as in <html>
 >     ...
 > </html>
 > 
 > or
 > <html xmlns="http://www.w3.org/1999/xhtml">
 >     ...  </html>
 > 
 > Without success, I tried things like: <html> <if test="$cond">
 > <xsl:namespace name="">http://www.w3.org/1999/xhtml</xsl:namespace>,
 > but cannot output a namespace node for the default namespace when the
 > element is in no namespace <!-- or <xsl:namespace
 > name="xmlns">http://www.w3.org/1999/xhtml</xsl:namespace>, but then
 > xmlns name is not acceptable,
 >                  or even 
 > <xsl:namespace>http://www.w3.org/1999/xhtml</xsl:namespace>, but the 
 > name attribute is required  -->
 > </if>
 >   ...  </html>
 > 
 > The following may also have been nice, if it created a namespace node
 > rather than an xmlns attribute: <html xmlns="if ($cond) then
 > 'http://www.w3.org/1999/xhtml' else '' ">
 >      ...  </html>
 > 
 > 
 > I understand that I could probably put the body of the html element
 > in a template (e.g. html-body), define all the (tons of) required
 > parameters, and do something like:
 > 
 > <xsl:choose> <xsl:when test="$cond"> <html
 > xmlns="http://www.w3.org/1999/xhtml"> <xsl:call-template
 > name="html-body"> <xsl:with-param name="xxx" select="abc"/>
 >                  ...
 > </xsl:call-template>
 > </html>
 > </xsl:when>
 > <xsl:otherwise>
 > <html>
 > <xsl:call-template name="html-body">
 > <xsl:with-param name="xxx" select="abc"/>
 >                  ...  </xsl:call-template> </html> </xsl:otherwise>
 > </xsl:choose>
 > 
 > But, especially as this would seem like a common case, I am sincerely
 > hoping that there is a better way.  How should this be better
 > handled?
 > 

What about this?

	<xsl:variable name="namespace">
		<xsl:if test="$cond">
			<xsl:text>http://www.w3.org/1999/xhtml</xsl:text>
		</xsl:if>
	</xsl:variable>

		<xsl:element name="html" namespace="{$namespace}">
			... Content ...
		</xsl:element>

-- 
Piet van Oostrum
Cochabamba. URL: http://pietvanoostrum.com/
Nu Fair Trade woonartikelen op http://www.zylja.com

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.