[xsl] Re: Generate key with further restriction

Subject: [xsl] Re: Generate key with further restriction
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 8 Sep 2003 21:06:06 +0200
> How can I generate keys with certain restrictions?
> Would something like that
> <xsl:key name="usedTypes" match="@*[name() = 'type' and
> not(starts-with(name(),'xs:'))]" use="." />
> work to select those attributes with the name type that do not start
> with xs: ?

   name() = 'type'

then it is impossible that


   name() = 'type' and  not(starts-with(name(),'xs:'))

is equivalent to the shorter and more understandable:

   name() = 'type'

Probably you wanted to use the function local-name() instead of name()

But then the same namespace-uri may be associated to another prefix, let's
say "ys", and the above (corrected) predicate will be true for that
attribute node.

Therefore, the correct way to ensure that a particular name does not belong
to a given namespace is to use the namespace-uri of the namespace:


  local-name() = 'type' and not(namespace-uri() = 'someNamespaceURI')

Or, if you want the name not to belong to any namespace, then use:

  local-name() = 'type' and not(namespace-uri())

Finally, if you just want the name to be "type" and you do not care about
any namespace this name may belong to, use:

  name() = "type"

> Do I need to take care of namespaces? How?

It depends on the specific problem you're solving, but usually the answer is
positive (otherwise the problem is either very generic or using namespaces
in the source.xml was up to no purpose).


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread