I am creating a xsl stylehseet and came up with this (in my opinion illogical behavior):
This XPath:
/root/element[1][@attr1 != '1' or @attr2 != 'test']
is WAY slower than this XPath:
/root/element[count(preceding-sibling::element) + 1 = 1) and (@attr1 != '1' or @attr2 != 'test')]
I have 50 sample xml and with the first XPath it takes ~55sec.
With the second XPath it takes ~4sec!
I use the XslCompiledTransform (C# .NET 4.5).
Can someone explain why the first XPath is THAT much slower than the second? I always thought it is better to use the explicit index filter.
Update: Some sample xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<element attr2="test" attr1="1">
<child>17</child>
<child>17</child>
<child>16</child>
...
<child>3</child>
<child>2</child>
<child>1</child>
</element>
<element attr2="test2" attr1="2">
<child/>
<child/>
<child/>
<child/>
<child/>
<child/>
<child/>
...
<child/>
</element>
....
<element attr2="test21" attr1="21" />
There are only like 20-25 elements with n childs but the depth maximum is 4 (/root/element/child/anotherChild).