[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how to select elements in a given namespace?

Subject: Re: how to select elements in a given namespace?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 17 Mar 2003 21:59:30 +0100
xpath select last
"Robert P. J. Day" <rpjday@xxxxxxxxxxxxxx> wrote in message
news:Pine.LNX.4.44.0303171505250.12433-100000@xxxxxxx
>
>   [xpathtester is steadfastly refusing to be helpful since it does
> not highlight selected nodes based on attributes or namespaces.]
>
>   from tidwell's book, if i have an excerpt from an XML file:
>
>   <auth:author xmlns:auth=...>
>    <last-name>...
>    <first-name>...
>    <nationality>...
>    <year-of-birth>...
>    <year-of-death>...
>   </auth:author>
>
> if i want to select all nodes in a given namespace ("auth"), it
> appears i can use:
>
>   //namespace::auth
>
> and while xpathtester refuses to highlight the matches, it does at least
> tell me there were 6 of them.  i'm assuming that these matches are the
> auth:author element itself, and the 5 children, right?

No, elements are not namespace nodes. These are:

  -  the namespace node with name (prefix) "auth" of auth:author

  -  the namespace nodes with name (prefix) "auth" of the children of
auth:author.

In XPath 1.0 if a namespace node belongs to an element, namespace nodes with
the same name (prefix) and namespace-uri belong to each of its descendent
elements.

This is no longer so in XPath 2.0 (I think), where the namespace nodes
associated with an element are "shared" or "visible" by all of its
descendent elements, but the descendent elements do not "have their own
copies".

>
>   so what is the XPath expression to match, say, the <last-name> elements
> within this namespace?

There is no "last-name" element in this namespace -- in your example. The
"last-name" element has a namespace node named "auth", but it does not
belong to this namespace. An element typically can have more than one
namespace, but belongs either to no namespace or at most to one namespace.

To match the "last-name" element from your example (which is in no
namespace), use:

//auth:author/last-name


Note that the tool that is used to perform the evaluation of the above XPath
expression must be provided with the proper definition of the "auth"
namespace or be clever enough to deduct it from the source xml document
(this is what the XPath Visualizer does).

In your own stylesheets you must have declared the "auth" (or another
prefix) namespace with exactly the same namespace-uri as used in the source
xml document. Only then the xpath expression above will "work".

The above XPath expression is evaluated successfully by the XPath
Visualizer, but only because it does behind the scene things as e.g.
dynamically copying all namespace definitions from the source xml document
into the stylesheet that is used to evaluate the XPath expression and return
the hi-lighted result.


=====
Cheers,

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




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.