diff --git a/src/MicrodataDOMElement.php b/src/MicrodataDOMElement.php index aec06d3..05493cb 100644 --- a/src/MicrodataDOMElement.php +++ b/src/MicrodataDOMElement.php @@ -14,7 +14,11 @@ class MicrodataDOMElement extends \DOMElement $tokens = $this->tokenizeAttribute('itemref'); foreach ($tokens as $token) { - // @todo Implement xpath query and get the first item + $references = $this->ownerDocument->xpath->query('//*[@id="'.$token.'"]'); + + if ($first = $references->item(0)) { + $pending[] = $first; + } } } diff --git a/tests/MicrodataParserTest.php b/tests/MicrodataParserTest.php index ffde0e7..6d5a567 100644 --- a/tests/MicrodataParserTest.php +++ b/tests/MicrodataParserTest.php @@ -67,6 +67,9 @@ class MicrodataParserTest extends \PHPUnit\Framework\TestCase 'W3C Example' => [ $this->getTestData('W3C', 'source.html', 'result.json') ], + 'Itemref & src based tags' => [ + $this->getTestData('Itemref', 'source.html', 'result.json') + ], ]; } diff --git a/tests/data/Itemref/result.json b/tests/data/Itemref/result.json new file mode 100644 index 0000000..b93b190 --- /dev/null +++ b/tests/data/Itemref/result.json @@ -0,0 +1,20 @@ +{ + "items": [ + { + "type": [ "http://n.whatwg.org/work" ], + "properties": { + "work": [ "http://blog.example.com/gallery/images/house.jpeg" ], + "title": [ "The house I found." ], + "license": [ "http://www.opensource.org/licenses/mit-license.php" ] + } + }, + { + "type": [ "http://n.whatwg.org/work" ], + "properties": { + "work": [ "http://blog.example.com/gallery/images/mailbox.jpeg" ], + "title": [ "The mailbox." ], + "license": [ "http://www.opensource.org/licenses/mit-license.php" ] + } + } + ] +} diff --git a/tests/data/Itemref/source.html b/tests/data/Itemref/source.html new file mode 100644 index 0000000..40dd9c9 --- /dev/null +++ b/tests/data/Itemref/source.html @@ -0,0 +1,23 @@ + + + + + Photo gallery + + +

My photos

+
+ A white house, boarded up, sits in a forest. +
The house I found.
+
+
+ Outside the house is a mailbox. It has a leaflet inside. +
The mailbox.
+
+ + +