Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selecting elements

 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • 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.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Will Thomas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic