aspose file tools*
The moose likes XML and Related Technologies and the fly likes selecting elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "selecting elements " Watch "selecting elements " New topic
Author

selecting elements

shankar vembu
Ranch Hand

Joined: May 10, 2001
Posts: 309
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

Joined: Jun 06, 2002
Posts: 1056
You need to replace < by &lt;
sum($colList/col[position() &lt; 3])
[ July 01, 2003: Message edited by: Ron Newman ]

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
shankar vembu
Ranch Hand

Joined: May 10, 2001
Posts: 309
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

Joined: Jul 02, 2003
Posts: 2
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.


Will Thomas<br />Software Engineer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: selecting elements