Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - why is count(xpath) != xpath[last()] ? >Thread Next - Re: why is count(xpath) != xpath[last()] ? Re: why is count(xpath) != xpath[last()] ?To: NULL Date: 12/12/2007 4:49:00 PM jfrensen@h... wrote: > <?xml version="1.0" encoding="UTF-8"?> > <root> > <Students> > <row> > <Name>Bob</Name> > </row> > <row> > <Name>Joe</Name> > </row> > </Students> > </root> > Note that the XPath /root/Students/row/Name yielded a nodeset of two > names, as shown by the value of both Count and AllNames. But the > expression > /root/Students/row/Name[position() = last()] did not evaluate to the > second name. That's because Name elements aren't siblings. Each Name element is the only Name element row element contains, so at the point when Name element is selected, context node-set contains single Name element, so last() = 1. > Even more strangely, /root/Students/row/Name[1] and / > root/Students/row/Name[last()] yielded the same result, even though > the nodeset in question contains two names. last() function returns context node-set size. During XPath expression evaluation context node-set is changing by each location step and predicate. You need (/root/Students/row/Name)[position() = last()] -- Oleg Tkachenko [XML MVP, MCPD] http://www.tkachenko.com/blog | http://www.XmlLab.Net | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
