XPath puzzler

While I’ve got your attention, here’s an XPath (1.0) puzzler. I have an RDFa dataset compiled from various and sundry sources. It’s all wrapped up in a single XML file. I run this XPath to see how many meta elements are present: //meta and it returns a node-set of size 762. Now, I want to see how many property elements are present, so I run the query: //meta/@property and it returns a node-set of size 764. How is it that the second node-set can be bigger than the first? -m

5 Responses to “XPath puzzler”

  1. M. David Peterson http://xmlhacker.com/

    Are the property attributes potentially in different namespaces, and your XPath engine is returning all matches on local-name() as opposed to name()? It’s possible that <meta foo:property=”bar” bar:property=”baz”/> on one or two of your meta elements is causing the increase.

    If you try //meta[@property] your count should be something equal to or less than the total count of the meta elements. If it’s not, then there’s really something weird going on.

  2. Dimitre Novatchev http://fxsl.sf.net

    Do try with different XPath engines in order to determine if the observed result is only produced by your XPath engine, in which case this is a clear indication of a bug. If most/all XPath engines report the observed result, could you, please, provide the xml file against which the XPath expression is evaluated?

    Dimitre Novatchev

  3. Tom Passin

    You would get this if some of the meta elements had more that one property attribute. Since that wouldn’t be well-formed, and the xslt processor shouldn’t be receiving multiple attributes of the same name, let alone be counting them, it would indicate one or more bugs, in the parser and in the xslt processor.

  4. Anthony B. Coates http://kontrawize.blogs.com/kontrawize/

    Can you post the dataset (with the data text replaced by some bogus text if necessary to protect the contents)?
    Cheers, Tony.

  5. Push Button Paradise | Blog Archive | XPath puzzler: solution http://dubinko.info/blog/2007/12/31/xpath-puzzler-solution/

    […] to all the folks who showed interest in this little XPath puzzler published here a few weeks ago. Some asked to see the dataset, but I’m not able to release it […]