cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sreedhar Chintalapaty" <schintalap...@ptc.com>
Subject RE: XSP Expression within XSL:for-each loop
Date Fri, 24 May 2002 13:09:39 GMT
Finally I found a solution, and it has nothing to do with Cocoon. The XSL
fragment in my question is part of an XSL template, and is preceded by two
statements loading two different xml files as a documents and querying for a
value in them. Later, another template uses "position()" to mark the
positions of gvs-list elements returned by the java method call and created
the HTML for select list. I could make it work by using "position() div
number('2')" instead of "position()" to do this indexing. If I load another
document prior to <uti-include-expr>, I will have to change it to
"position() div number('3')" to make it work, and so on.

But I don't understand -why- this works. Can some one enlighten me?

Sreedhar

-----Original Message-----
From: Sreedhar Chintalapaty [mailto:schintalapaty@ptc.com]
Sent: Monday, May 20, 2002 9:55 AM
To: Cocoon Users
Subject: XSP Expression within XSL:for-each loop


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: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>



---------------------------------------------------------------------
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: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>


Mime
View raw message