Re: [xml] XPath question



On Wed, Aug 04, 2004 at 11:45:29AM -0400, Jesse Pelton wrote:
So how do you solve the original problem?  That is, how do you construct
an expression to select elements in a particular default namespace? 
recap:
   <doc>
     <a xmlns="some-ns">
       <n/>
     </a>
     <b xmlns="another-ns">
       <n/>
     </b>
   </doc>
problem:
        get the second "n" node.
solution:
        define prefix X => another-ns
        if you happen to be in a xsl stylesheet something like
        <xsl:template xmlns:X="another-ns" ...

        The xpath is:
        //X:n

The prefix in the xpath does not have to be the same as the prefix in
the document.

otoh, if you had instead: (note that there is NO xmlns= declaration)
<doc>
<Y:b xmlns:Y="another-ns">
        <n/>
</Y:b>
</doc>
        you'd need: //X:b/*[local-name()='n']
because then the element 'n' is not in any namespace.  (which is completely
different from the default namespace)

eric



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]