[...How to match elements from different namespaces...]
<xsl:template match="a:element">
...
<xsl:template match="b:element">
...
together with
xmlns:a="goop"
xmlns:b="gleep"
Thank you: That is a very clear answer.
I simplified too much. My problem is a little more bizarre.
I'm not even sure if this is legal xml, but this is what I'm trying to deal
with:
My document contains elements like this:
<document xmlns="MyStuff">
....
<fe:fragment xmlns="goop" xmlns:fe="Fragment" fragment-id="123"/>
....
<fe:fragment xmlns="gleep" xmlns:fe="Fragment" fragment-id="456"/>
....
</document>
The stylesheet root element looks like this:
<xsl:stylesheet version="1.0"
xmlns="
http://www.w3.org/1999/xhtml"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:fe="Fragment"
I want to write one template that matches the fe:fragment that contains
xmlns="goop" and one template that matches the fe:fragment the contains
the xmlns="gleep".
The fe:fragments are created by a piece of software I don't entirely
control.
It seems to me that the fe:fragment elements have conflicting namepace
membership. Is this legal XML by itself:
<fe:fragment xmlns:fe="Fragment"/>
In other words, can you use a namespace prefix on an element that
contains the prefix definition? I though it could only be used by the
element's children...
I found that my stylesheet didn't work if I didn't define the fe prefix
in the stylesheet root.
And what does this mean:
<root xmlns:fe="Fragment">
<fe:fragment xmlns="goop" xmlns:fe="Fragment"/>
</root>
What is the namespace of fe:fragment?
Is the internal xmlns:fe="Fragment" necessary? Sufficient?
Is this legal xml at all?
In case you're interested in the larger context, the fe:fragments are
created by
by Apache Cocoon's FragmentExtractorTransformer. I have a source document
that I need to extract two different elements for processing by two
different external
Cocoon serializers. When a fragment extractors is configured, you specify
the element name you want to extract and the element's namespace URI.
The intermediate xml document is sent to the stylesheet with the elements
extracted and replaced by the <fe:fragment> elements shown above.
The stylesheet rearranges things a bit and the fragments go back to
the Cocoon pipeline where the original elements get looked up and their
content gets processed.
The only way to distinguish the fragments is by their id attribute and
by the xmlns="blah" they contain. The xmlns="blah" is the namespace
of the extracted element. The fragment does not explicity contain the
name of the element it replaced, which seems like a Bad Thing to me.
I need to handle the fragments differently in the stylesheet depending
on the element they came from. In my case, it happens that each
of the two elements is in a different namespace. So if I can
write the proper template, I can handle the fragments properly.
Thanks,
Hugh Sparks, (e-mail address removed)