I was not aware of "count(preceding-sibling)" function ,your code just worked fine.
I tried google what are the different option available in LibXML but could not find can u help me on that.
If wanted the output some thing like
VAL1,NAME,0
VAL1,NAME1,0
VAL2,NAME,0
VAL2,NAME1,0