We welcome you to a discussion already in progress.  Dan Allen
(that's me) brought up the issue that in the domxml extension, the
xpath_eval function does not allow you to begin the query relative
to a given node, as is possible in both the libxml2 libraries and as
we are so familiar with, in xslt.  It is simply a matter of having
either a function called

xpath_set_context_node()

or more simply a second parameter passed to xpath_eval() that allows
you to specify your "current" node.  This way, if you did the
expression '*' it would find the children relative to the starting
point, hence it would be a relative xpath expression.  You will find
below the discussion, hopefully this feature can be given attention
in the near future.

Daniel Veillard ([EMAIL PROTECTED]) wrote:

> On Wed, Jun 05, 2002 at 01:18:47AM -0700, Dan Allen wrote:
> > I have a question about xpath that I can't seem to resolve after
> > looking through the documentation for libxml2.  If I am to setup a
> > new xpath context and then run xpathEval it assumes that when I run
> > my query, I am starting from the top of the document.  However, in
> > xslt, when you run a select, you often use use a relative
> > query...such as
> > 
> > <xsl:template match="nodeName">
> >   <xsl:apply-templates select="*"/>
> > </xsl:template>
> > 
> > So effectively no matter where you are in the document you can run a
> > query relative to that position in xslt.  I was thinking, this could be
> > solved easy enough for domxml if there was a method on a node called
> > 
> > getXPathLocation
> 
> Indeed there is, and it is called xmlGetNodePath
>
> /**
>  * xmlGetNodePath:
>  * @node: a node
>  *
>  * Build a structure based Path for the given node
>  *
>  * Returns the new path or NULL in case of error. The caller must free
>  *     the returned string
>  */
> xmlChar *
> xmlGetNodePath(xmlNodePtr node)
>   
> > or something that just works recursively up until you get the the
> > root of the document...sort of like in unix when you type
> > 
> > pwd
> > 
> > you get your current path... You might have done
> > 
> > cd /var/log/../../home/dallen/../../usr/share
> > 
> > but your present working directory will still come up as /usr/share
> > So then you could just say...
> > 
> > $ctx->xpath_eval('*', $node->xpathLocation);
> > 
> > Where $node is just an DOMElement object for example and the second
> > parameter to xpath_eval is a path which is appened to the query...or
> > maybe just require that the user paste the query together himself.
> > Would it be slower to have to look through the whole document
> > though?  Maybe by passing in the context location, you can speed up
> > the query by eliminating the current location and just starting from
> > there.
> 
>   yes to set up the current node (or current doc) for an XPath query
> you need to access the XPath context and set those informations:
> 
>     xmlXPathContextPtr ctx;
> 
>     ctx->doc = my_document;
>     ctx->node = my_current_node;
> 
> > I'm I way off here or do I sound like I make some sense?  I am not
> 
>   makes some sense, yes.
> 
> Daniel
> 
> -- 
> Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
> [EMAIL PROTECTED]  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

-- 
________________________________________________________________
Daniel Allen, <[EMAIL PROTECTED]>
http://www.mojavelinux.com/
________________________________________________________________
"I used to herd dairy cows.  Now I herd linux users.  Apart 
from the isolation, I think I preferred the cows.  They were 
better in conversation, easier to milk, and if they annoyed me 
enough, I could shoot them and eat them."
________________________________________________________________

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to