This seemed to work:

<%@ page contentType="text/plain" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml"; %>

<x:parse var="doc">
<parent><child/><child/><child/><child/></parent>
</x:parse>

<x:set var="child1" select="$doc//parent/child[1]"/>
<x:set var="child4" select="$doc//parent/child[4]"/>

child1: <x:out select="count($child1/preceding-sibling::child) + 1"/>
child4: <x:out select="count($child4/preceding-sibling::child) + 1"/>

Of course, if you had elements like <child id="1"/>, it would be even easier to
get at:

child1: <x:out select="$child1/@id"/>

Quoting Michael Duffy <[EMAIL PROTECTED]>:

> 
> If I have an XML stream like this:
> 
> <parent><child/><child/><child/><child/></parent>
> 
> I can refer to each child individually using XPath:
> 
> //parent/child[1] gives me the first child,
> //parent/child[2] gives me the second child, 
> etc.
> 
> When I use JSTL <xml> tags, is it possible to get that
> ID number out?  I've got a List of child tags that I
> want to use in an HTML checkbox input, and I'd like to
> be able to identify selected items by their ID. 
> Thanks - MOD

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to