Re: default or no namespace
On 28 December 2010 07:02, ac <ac@xxxxxxxxxxxxx> 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 ... > 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:otherwise> > <html> You can't do either because the namespace is applied at the xml level, not at the xslt level. In other words, the default namespace would only be changed for the children of <html> in the xml that is your stylesheet, not in the constructed result. The usual technique is to have an identity transform as the last step to put the elements into the xhtml namespace (use modes if you want to keep it all in a single transform). -- Andrew Welch http://andrewjwelch.com
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format