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.
-Bill
-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 12, 2001 10:40 PM
To: [EMAIL PROTECTED]
Subject: Re: xtag:context and xtag:variable
HI William
From: "William C. Robertson" <[EMAIL PROTECTED]>
>
> <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.
e.g.
<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">
</xtags:context>
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
specified.
> Is the list a list in the sense of a "linkedList" or part of the io
package?
> 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
documentation.
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:
string
number
list
object
node
The real class names are
java.lang.String
java.lang.Number
java.util.List
java.lang.Object
org.dom4j.Node
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
a
> 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...
XML...
<customers>
<customer>
<name>william</name>
<location>?</location>
</customer>
<customer>
<name>james</name>
<location>London</location>
</customer>
</customer>
<xtags:forEach select="/customers/customer" sort="name" distinct="true">
Name: <xtags:valueOf select="name"/>
Location: <xtags:valueOf select="location"/>
</xtags:forEach>
Where the sort attribute is another XPath expression, evaluated on each
resulting node and is used for the comparison.
Does that help at all?
James
_________________________________________________________ Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com