xsl-list
[Top] [All Lists]

RE: unwanted xmlns="" attribute

2004-10-01 09:53:49
If you sometimes want to generate an {xx}help element, and sometimes a
{yy}help element, where {xx} and {yy} are different namespaces, then you
need to use conditional logic that changes the element name: in XSLT 2.0 you
can write

<xsl:element name="help" namespace="{if ($param} then '' else
'http://purl.org/rss/1.0/'}>

In XSLT 1.0 you will need to use xsl:choose. The caller of the template will
need to supply an explicit parameter saying which namespace is required.
There is no way of generating an element and saying simply "put this in the
same namespace as its new parent".

Namespaces are not attributes. The namespace is part of the element name,
even though it is not written explicitly as such. You have full control when
you generate an element over both the local name of the element and its
namespace name. The serializer will automatically generate namespace
declarations that respect the namespaces in which you have placed your
constructed elements.

It seems a rather unusual requirement to have a template that sometimes
generates an {xx}help element, and sometimes a {yy}help element, where {xx}
and {yy} are different namespaces, because the meaning of local names like
"help" depends entirely on which namespace they are in, and the names in one
namespace are usually unrelated to those in a different namespace.

Regards,

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: tom tom [mailto:tomxsllist(_at_)hotmail(_dot_)com] 
Sent: 01 October 2004 17:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] unwanted xmlns="" attribute

Thankyou, this solves half of my problem.

However the included file is also included from a second XSLT 
file with 
contains no existing namespace references. If I add  
xmlns="http://purl.org/rss/1.0/"; to <help> this renders as <help 
xmlns="http://purl.org/rss/1.0/"/> - I do not want the 
attribute to appear 
in the second file.




From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] unwanted xmlns="" attribute
Date: Fri, 1 Oct 2004 16:35:58 +0100

When you say you don't want the xmlns="" to appear on the 
<help/> element,
what you presumably mean is that you want the <help> element 
to be in the
namespace "http://purl.org/rss/1.0/";. The answer is to put it in that
namespace, for example by writing it in the stylesheet as

<help xmlns="http://purl.org/rss/1.0/"/>

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: tom tom [mailto:tomxsllist(_at_)hotmail(_dot_)com]
Sent: 01 October 2004 15:47
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] unwanted xmlns="" attribute

In my including file I have:

<xsl:template match="test">
  <rdf:RDF xmlns="http://purl.org/rss/1.0/";
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
xmlns:dc="http://purl.org/dc/elements/1.1/";>
          <xsl:apply-templates select="." mode="testy"/>
  </rdf:RDF>
</xsl:template>

In my included file I have:

<xsl:template match="test" mode="testy">
  <help/>
</xsl:template>

My output comes out as:

<rdf:RDF xmlns="http://purl.org/rss/1.0/";
xmlns:dc="http://purl.org/dc/elements/1.1/";
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";>
  <help xmlns=""/>
</rdf:RDF>


I do not want the xmlns="" attribute to appear on the help
element. I have
tried numerous permutations using the exclude-result-prefixes on
xsl:stylesheet to no avail. I am using MSXML 3. Can anyone advise?

_________________________________________________________________
Express yourself with cool new emoticons
http://www.msn.co.uk/specials/myemo



--+------------------------------------------------------------------
XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger 
http://www.msn.co.uk/messenger


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--