hello dear php-experts
Getting attribute using XPath :: How can I match on an attribute that contains a certain string?
i Use:
/html/body/div[7]/div/section/div/section/div/div[1]/h3
This means:
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():
string(/html/body/div[7]/div/section/div/section/div/div[1]/h3)
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
[upl-image-preview url=https://board.phpbuilder.com/assets/files/2020-03-14/1584227270-596919-image.png]
[upl-image-preview url=https://board.phpbuilder.com/assets/files/2020-03-14/1584227333-544188-image.png]
i look forward to hear from you