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 Replies to “XPath puzzler”
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.
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?
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.
Can you post the dataset (with the data text replaced by some bogus text if necessary to protect the contents)?
Comments are closed.