tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William C. Robertson" <>
Subject RE: xtag:context and xtag:variable
Date Fri, 13 Jul 2001 21:27:02 GMT
Thanks for your reply.  I thought about the "superfluous" quality of context
and I can't come up with a case where forEach would not work equally well.

For xtags.variable, need I only specify: node="list" to load a
Java.util.List class loaded with the results of a select?

Thank you for elucidating the use of the "distinct" operator in xpath, I am
now able to simplify my xml docs and speed up my code (the zvon tutorial
doesn't cover that attribute).

Thanks again for your reply and thanks for all your work.


-----Original Message-----
From: James Strachan []
Sent: Thursday, July 12, 2001 10:40 PM
Subject: Re: xtag:context and xtag:variable

HI William

From: "William C. Robertson" <>
> <xtag:context> does not seem to behave the same as it's cousin
> <xtag:forEach>.  For the same path, forEach works but context doesn't.  Is
> there something I'm missing?

<xtags:forEach> is meant to loop whereas <xtags:context> isn't but you're
right apart from that they should be similar.

Do you have an example of something that doesn't work?

<xtags:context> is more intended to help factorize the use of XPath.


<xtags:valueOf select="/customers/customer[@id='123']/name">
<xtags:valueOf select="/customers/customer[@id='123']/address">
<xtags:valueOf select="/customers/customer[@id='123']/email">

Could be

<xtags:context select="/customers/customer[@id='123']">
    <xtags:valueOf select="name">
    <xtags:valueOf select="address">
    <xtags:valueOf select="email">

Strictly speaking the above could be accomplished with <xtags:forEach>
instead, the <xtags:context> tag is kinda superfluous but some users liked
it as it explicitly will not loop.

> <xtag:variable> will return "an Object or List" if "node" is not
> Is the list a list in the sense of a "linkedList" or part of the io
> Where can I find out about how to use it?

I'm in the middle of converting xtags over to the new build process and as a
result I've been doing much more documentation on the attributes used in the
tags, so hopefully in a few days time you'll have some much better

Part of the problem is that an XPath expression could result in a String,
Number, Boolean, List or Node. So there is a type attribute to indicate what
type of variable you want. I've found most of the time people want Strings
so I've made string the default. Also it can get a bit ugly using the real
Java class names in JSP so I added some simple aliases as an option as well.

The alias names are:


The real class names are


One of the main reasons for the <xtags:variable> tag is so that an XPath
expression can be evaluated and the resulting object can be reused several
times by passing it in as the context into other tags like <xtags:forEach>
or <xtags:valueOf>.

> I am currently loading a string array to step through because I haven't
> found an XPath alternative to SQL's "DISTINCT" operator.  Does anyone have
> more elegant solution?

The <xtags:forEach> tag has sorting and removing distincts built in. So if
you want to iterate through your customers, in name order removing
duplicates the following should work...



<xtags:forEach select="/customers/customer"  sort="name" distinct="true">
    Name: <xtags:valueOf select="name"/>
    Location: <xtags:valueOf select="location"/>

Where the sort attribute is another XPath expression, evaluated on each
resulting node and is used for the comparison.
Does that help at all?


 _________________________________________________________ Do You Yahoo!?
Get your free address at

View raw message