What is the correct syntax for applying string functions (e.g. "normalize-space") on a attribute using the xpath query below?
Query: "./@media"
I've seen examples of this elsewhere but if I try it using php's xpath library it returns nothing...
What is the correct syntax for applying string functions (e.g. "normalize-space") on a attribute using the xpath query below?
Query: "./@media"
I've seen examples of this elsewhere but if I try it using php's xpath library it returns nothing...
How about this?
normalize-space(./@media)
You could also try:
normalize-space(string(./@media))
but I don't think that's neccessary here.
Using query() on a DOMXPath object will always result in a node-set (wrapped in a DOMNodeList object), never in a string.
You can't pull out the results of XPath functions. You must query the nodes you want to process, and process them in PHP.
Use evaluate() instead of query()
. It will return a typed result. It's available since PHP 5.1.
$doc = new DOMDocument();
$xpath = new DOMXpath($doc);
$q = $xpath->evaluate('"test"');
var_dump($q);
output:
string(4) "test"