[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Can one element have more than one namespaces?
Hi Dave, > So the answer is no? I can't differentiate between the two elements > in my example, since the only difference is the 'extra namespace in > scope', Your example was: > given two different elements, > element A in ns X and Y > element A in ns X > > How do I do a template match to select the first one? Chris explained that there can be no such thing as 'element A *in* ns X and Y' as an element can only ever be *in* one namespace. Perhaps you meant: element A with ns declarations for X and Y element A with ns declaration for X In other words, something like: <B> <A xmlns:x="X" xmlns:y="Y" /> <A xmlns:x="X" /> </B> or: <B xmlns:x="X"> <A xmlns:y="Y" /> <A /> </B> (Note that the A and B elements are all in the *null* namespace in this example - they don't have prefixes, and there's no default namespace declaration.) > Can't the namespace axis be used for this purpose? Yes, the namespace axis can be used to differentiate between nodes that have different namespaces *in scope*. You can match the A element that has namespace declarations for both X and Y with the template: <xsl:template match="A[namespace::x and namespace::y]"> ... </xsl:template> Note that the 'x' and 'y' (the namespace prefixes) come from the *source* XML document, not from the declarations in the XSLT stylesheet. So the above template would work even if the stylesheet declared the X and Y namespaces with completely different prefixes, or didn't declare them at all. However, if you changed the prefixes in the source to a and b instead: <B xmlns:a="X"> <A xmlns:b="Y" /> <A /> </B> Then the match pattern wouldn't match either A element because neither has namespaces with the prefixes 'x' or 'y'. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|