You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Michael Duffy <du...@yahoo.com> on 2004/01/23 15:01:29 UTC
Getting XPath ID From A List Of Child Tags
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
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting XPath ID From A List Of Child Tags
Posted by Kris Schneider <kr...@dotech.com>.
Not a problem, glad it'll work.
Quoting Michael Duffy <du...@yahoo.com>:
>
> Of course you're correct, Kris. I'm going too fast
> and not thinking enough. Thanks again for the great
> advice, and I'm sorry to bother you. Sincerely, MOD
>
>
> --- Kris Schneider <kr...@dotech.com> wrote:
> > I guess it all depends on what you mean by "ID
> > values". I interpreted it as
> > equivalent to the position with respect to the
> > parent:
> >
> > <parent>
> > <child/> <!-- id=1 -->
> > <child/> <!-- id=2 -->
> > <child/> <!-- id=3 -->
> > <child/> <!-- id=4 -->
> > </parent>
> >
> > So, counting the number of preceding "child"
> > siblings seemed appropriate. Did
> > you have something else in mind?
> >
> > Quoting Michael Duffy <du...@yahoo.com>:
> >
> > > Thanks, Kris.
> > >
> > > I don't want to get the child value - that's easy
> > > enough. I want to get their ID values. It
> > doesn't
> > > appear that your code is doing that, but then
> > again
> > > I'm the guy who doesn't know how. Maybe I don't
> > > recognize correct code when I see it. ;)
> > >
> > > Am I misunderstanding here? I'll apologize in
> > advance
> > > if that's so. - MOD
> > >
> > >
> > > --- Kris Schneider <kr...@dotech.com> wrote:
> > > > 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 <du...@yahoo.com>:
> > > >
> > > > >
> > > > > 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 <ma...@dotech.com>
> > > > D.O.Tech <http://www.dotech.com/>
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting XPath ID From A List Of Child Tags
Posted by Michael Duffy <du...@yahoo.com>.
Of course you're correct, Kris. I'm going too fast
and not thinking enough. Thanks again for the great
advice, and I'm sorry to bother you. Sincerely, MOD
--- Kris Schneider <kr...@dotech.com> wrote:
> I guess it all depends on what you mean by "ID
> values". I interpreted it as
> equivalent to the position with respect to the
> parent:
>
> <parent>
> <child/> <!-- id=1 -->
> <child/> <!-- id=2 -->
> <child/> <!-- id=3 -->
> <child/> <!-- id=4 -->
> </parent>
>
> So, counting the number of preceding "child"
> siblings seemed appropriate. Did
> you have something else in mind?
>
> Quoting Michael Duffy <du...@yahoo.com>:
>
> > Thanks, Kris.
> >
> > I don't want to get the child value - that's easy
> > enough. I want to get their ID values. It
> doesn't
> > appear that your code is doing that, but then
> again
> > I'm the guy who doesn't know how. Maybe I don't
> > recognize correct code when I see it. ;)
> >
> > Am I misunderstanding here? I'll apologize in
> advance
> > if that's so. - MOD
> >
> >
> > --- Kris Schneider <kr...@dotech.com> wrote:
> > > 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 <du...@yahoo.com>:
> > >
> > > >
> > > > 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 <ma...@dotech.com>
> > > D.O.Tech <http://www.dotech.com/>
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> taglibs-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting XPath ID From A List Of Child Tags
Posted by Kris Schneider <kr...@dotech.com>.
I guess it all depends on what you mean by "ID values". I interpreted it as
equivalent to the position with respect to the parent:
<parent>
<child/> <!-- id=1 -->
<child/> <!-- id=2 -->
<child/> <!-- id=3 -->
<child/> <!-- id=4 -->
</parent>
So, counting the number of preceding "child" siblings seemed appropriate. Did
you have something else in mind?
Quoting Michael Duffy <du...@yahoo.com>:
> Thanks, Kris.
>
> I don't want to get the child value - that's easy
> enough. I want to get their ID values. It doesn't
> appear that your code is doing that, but then again
> I'm the guy who doesn't know how. Maybe I don't
> recognize correct code when I see it. ;)
>
> Am I misunderstanding here? I'll apologize in advance
> if that's so. - MOD
>
>
> --- Kris Schneider <kr...@dotech.com> wrote:
> > 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 <du...@yahoo.com>:
> >
> > >
> > > 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 <ma...@dotech.com>
> > D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting XPath ID From A List Of Child Tags
Posted by Michael Duffy <du...@yahoo.com>.
Thanks, Kris.
I don't want to get the child value - that's easy
enough. I want to get their ID values. It doesn't
appear that your code is doing that, but then again
I'm the guy who doesn't know how. Maybe I don't
recognize correct code when I see it. ;)
Am I misunderstanding here? I'll apologize in advance
if that's so. - MOD
--- Kris Schneider <kr...@dotech.com> wrote:
> 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 <du...@yahoo.com>:
>
> >
> > 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 <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> taglibs-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting XPath ID From A List Of Child Tags
Posted by Kris Schneider <kr...@dotech.com>.
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 <du...@yahoo.com>:
>
> 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 <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org