Hi Gurus,
I have a piece of code with the following for-each loop:
<xsl:for-each select="document('actions.xml')/actions/action">
<xsl:variable name="target-class">
<xsl:value-of select="@class"/>
</xsl:variable>
<util:include-expr>
<util:expr>
<xsp:expr>
<xsl:value-of select="$target-class"/>.getAll()
</xsp:expr>
</util:expr>
</util:include-expr>
</xsl:for-each>
The intention is to determine the class name at run time and get all
persistent objects of that class from the database.
The reality is that the <util:include-expr></util:include-expr> part is
using only the very first $target-class value, even though the $target-class
value is different for different action elements. Of course, if I just print
out the value of the variable target-class right before entering the
<util:include-expr></util:include-expr>, it prints out all the different
values, as it should.
When I look into the generated class, here's what I find (assuming target
class is Singer, and excluding fully qualified class names):
1. {
2. Parser newParser = null;
3. try {
4. newParser = (Parser) this.manager.lookup(Parser.ROLE);
5. InputSource __is = new InputSource(new
StringReader(String.valueOf(Singer.getAll())));
6. XSPUtil.include(__is, this.contentHandler, newParser);
7. } catch (Exception e) {
8. getLogger().error("Could not include page", e);
9. } finally {
10. if (newParser != null) {
11. this.manager.release((Component) newParser);
12. }
13. }
14. }
This code block is repeated for each value of $target-class, with the method
call Singer.getAll replaced with the correct value of $target-class - i.e.,
if $target-class = {Singer, Actor, Producer), the block above is repeated
thrice, with Singer.getAll(), Actor.getAll(), and Producer.getAll() as the
method calls in line 5.
That part is as it should be; but when I see the output, I actually see only
the results of Singer.getAll() appearing thrice! Is the finally clause
releasing the newParser in line 11 responsible for this?
How can I get this to work right? Am I missing something in the way I am
including the expression?
Thanks, and Best Regards,
Sreedhar
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>