Re: [xsl] Q: XSLT 1.0 output of namespace

Subject: Re: [xsl] Q: XSLT 1.0 output of namespace
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 17 Aug 2010 13:56:03 +0100
In getting to the solution below I found that
   ". = ../namespace::*[name()]"
as "is-namespace()" test is even simpler than Michael's
   "count(. | ../@*) != count(../@*)".

Similarly ". = ../attribute::*[name()]" can be used as "is-attribute()".


It might be simpler, but it's wrong. Firstly, the expression attribute::*[name()] is rather pointless: it selects all attribute that have a name, and all of them do. While namespace::*[name()] selects all namespaces except the default namespace, so your test will fail for that one.


Secondly, it's quite possible to have an attribute and a namespace with the same string-value, for example

<xs:schema xmlns:a="http://my.namespace/"; targetNamespace="http://my.namespace/";>

and in this case your test for a namespace and your test for an attribute will both return true.

Michael Kay
Saxonica

Current Thread