RE: Matching namespaces on source documents

Subject: RE: Matching namespaces on source documents
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Mon, 8 Nov 1999 12:25:48 -0700
To expand on Michael Kay's explanation...

> <xsl:template match="test:foo">

This says "this template matches elements with the local name
'foo' that have associated with them a namespace URI that has
been assigned to the 'test' prefix in this stylesheet" ... 
it does *not* say "this template matches elements designated
'test:foo' in the source document".

It's kind of confusing because you do have access to the
'test' prefix from the source document, but not in this way.

You're matching the namespace URI that 'foo' is assigned to,
not 'foo'. It might help if you consider what happens when
you don't use prefixes:

  <?xml version="1.0"?>
     <foo xmlns="";>hello world</foo>

How would you make a template match this foo? match="foo"
wouldn't work because the namespace URI is not null.
match="foo[namespace-uri(.)='']" would
probably work, but is inconvenient. So, you can declare
a prefix-to-namespace-URI assignment in your stylesheet:


and then use <xsl template match="mytest:foo">. The URIs have
to match between the stylesheet and source document. Whether
the prefixes do or don't is irrelevant.

One of the consequences of this is that there's apparently
no way of knowing whether the prefix assignment was done in
the stylesheet to aid in processing or if you're intending
to have the assignment appear in the result tree. Your
XSL processor might be inclined to put the assignment in the
output, even if the prefix is not used in the result tree.
The result tree would probably have to be reparsed after it
is built in order to determine whether the prefix is
actually needed. Then you're still left wondering what to do
if you wanted the prefix to be declared anyway...

Someone else may want to comment/correct me on this. I know
it has come up before.


 XSL-List info and archive:

Current Thread