hello dear php-experts
Getting attribute using XPath :: How can I match on an attribute that contains a certain string?
i have to select the attribute of the title element that is a child of the first child of
the top element of the XML document.
To get just the string value of this attribute use the standard XPath function string():
more basically the question is: How can I match on an attribute that contains a certain string
I am having a problem selecting nodes by attribute when the attributes contains more than one single word.
in other words: How could I get the value of the first element?
well i think that the above mentioned approach is just a good start but will fail if the mentioned tag is not the first classname listed.
The usual approach is the rather unwieldy:
//*[contains(concat(' ', @class, ' '), ' tag ')]
guess that this will just work as long as classes are separated by spaces only, and not other forms of whitespace.
This is almost always the case. If it might not be, then we have to make it more unwieldy still:
//*[contains(concat(' ', normalize-space(@class), ' '), ' tag ')]
(Selecting by classname-like space-separated strings is such a common case :: but well it is just surprising there isn't a specific XPath function for it,
like the basic CSS3's '[class="tag"]'.)
well i guess that this will work
i look forward to hear from you