• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

selecting elements

 
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this set of elements stored in a variable say colList.

Now I would like to do some summing operation for which I need to access some elements of the above list.
For example, I may have to sum up all the values for elements whose position is less than 3.
so, I would write something like this.
sum($colList/col[position()<3])
But, i am getting an error saying that attribute value may not contain '<'.It works fine for '>'. Does it mean I cant select elements which are below some position value??
From the XPath specs,I found this


child: ara[position()>1] selects all the para children of the context node other than the first para child of the context node


But is there no way to do something like this:
child: ara[position()<5] selects all the para children of the context node from position 1 to 4e
Or maybe I am missing something here!!
Regards,
Shankar.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to replace < by &lt;
sum($colList/col[position() &lt; 3])
[ July 01, 2003: Message edited by: Ron Newman ]
 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ron Newman:
You need to replace < by &lt;
sum($colList/col[position() &lt; 3])
[ July 01, 2003: Message edited by: Ron Newman ]


hello ron,
it works now. thanku. but i was wondering why it worked for
sum($colList/col[position() > 3]) without esacping the '>' symbol.
shankar.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the recommendation was developed, they needed to require one or the other (< or > to be escaped. Just so happens that they made it the <. This made it much more efficient for parsing.
 
Space pants. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic