Hello All,
I have a question regarding just what is supported by DOMXPATH that is driving me mad: I cannot get any string functions (maybe number too) to work. Actually, I am modifying this post a little after completing some successful tests. It may be that it is not an issue with DOMXPATH but an XPATH question. I'm not sure, so I'm pressing ahead and hoping for your help.
I was initially going to post that string functions do not work using DOMXPATH, but I see that they DO work when they are part of a predicate, but I cannot get them to RETURN values as results. For example:
Given the XML snippet here:
<library name="mylibrary">
<books name="booklist">
<book name="To Kill A Mockingbird"/>
<book name="Pro Drupal Development"/>
</books>
</library>,
the XPATH expression //book/@name[substring(.,1,2)="To"] returns the <book> element with name "To Kill A Mockingbird".
What I actually want to do is to be able to have the value from a string function returned. So, I want to evaluate an expression such as:
//book/@name[substring(.,1,2)]
and have it return the result of the expression (i.e. "To"). How do I construct an XPATH query such that I obtain the results of expressions with string functions? Similarly to the example above, I might want to have the result of the concat/string-length/translate functions returned from a query...Am I doing something wrong and/or missing something fundamental when constructing my queries?
I've been googling for days with absolutely no luck, so I thought I would try here. There are so many XPATH tutorials available and so many of them mix XPATH 1.0 with XPATH 2.0 that I admit I was unaware for a time that DOMXPATH only supports XPATH 1.0. Also, they mostly show only simple expressions, never showing the use of functions, so I cannot get that feeling of confidence that even though they are not working for me, they work for everybody else.
Can anybody shed some light on this matter? Your help is greatly appreciated.
Thank you.