[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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"?>
  <document>
     <foo xmlns="http://www.test.org">hello world</foo>
  <document>

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(.)='http://www.test.org']" would
probably work, but is inconvenient. So, you can declare
a prefix-to-namespace-URI assignment in your stylesheet:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mytest="http://www.test.org">

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.

-Mike


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



Current Thread
Keywords
xsl