views:

54

answers:

3

Sitecore query is based on XPATH, but looks like it does not support count() function. My query is this:

../*[@@templatekey='topic' and count(child::*) > 0]

But gives me "Object reference not set to an instance of an object." error. But if I remove the count() filter, works just fine...

Any idea why it doesn't like count?

A: 

Try this:

../*[@@templatekey='topic' and *!=null]

Hope this helps.

Yan Sklyarenko
Wow. It worked. Didn't realize I could use null. Thanks mate.
Sudeep
A: 

Sitecore does like the count() method, but you have to pass it something valid to count. Are you sure your axis definition is correct for where you are? Also, depending on your current context then be careful of exactly what you are counting.

Simon
Yes, it is correct.
Sudeep
+1  A: 

Also were you using fast query? Count() or any other function won't work in fast mode.

Steve Green
Yes, fast query. Yes, found out fast query does not support count yet.
Sudeep