Sridhar,
At 04:05 PM 3/30/2004, you wrote:
<xsl:for-each select="key('act-name', $joinname)">
<xsl:copy-of select="key('act-name',
$joinname)"/>
</xsl:for-each>
This could simply be xsl:copy-of select="...": remove the for-each
instruction wrapper as it does nothing. (It selects the nodes which will be
copied, but does not copy them. If the wrapper is not there, they will
still be copied. Nodes that do not exist will not be copied in any case.)
But I think what I suggested before,
<xsl:apply-templates select="key('act-name', $joinname)" mode="join"/>
will work better. This is because then you can match the selected nodes
with another template like this:
<xsl:template match="activity-state" mode="join">
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
<xsl:apply-templates select="(some-other-node-set-you-want-to-retrieve)"/>
</xsl:template>
(Or perhaps you want the apply-templates to be inside the copy: it depends
on how you want the stuff to be assembled).
<!-- Check whether this contains reference to
another concurrent-block -->
<!-- If it is present then call the template once
again to process the concurrent-block subnode-->
<xsl:for-each select="key('con-name', $joinname)">
<xsl:call-template name="template1" />
<!-- This node is already populated
here.. Hence it should not -->
<!-- get populated when it is encountered
in the above loop -->
</xsl:for-each>
I think if you experimented with the approach above, you would find that
this latter bit of testing and traversing is not necessary.
Note that all my suggestions are along the same track: use templates, and
use the apply-templates instruction, nested inside your templates, to
control how you want the output document assembled from the input. Because
of the "recursive" nature of XSLT's template-matching processing model,
this is fully capable of handling, implicitly, the recursion you suggested
you needed in your first post. But, except for a scarce few lucky souls,
the XSLT processing model is not self-evident to most newcomers to the
language: it requires a bit of study, a bit of practice and perhaps an
"aha!" moment.
I haven't written you a detailed explanation of how XSLT templates work
since (a) this is basic knowledge, readily available in books or on line
(though an astonishing number of people apparently think they can write
XSLT without understanding what a template is, or the difference between
"select" and "match"), and (b) it is really a guess on my part that this is
the area where you need to concentrate your efforts to understand. (It
would be rude of me to assume you don't understand it: you're clearly smart
enough to master this stuff, which actually isn't all that hard; but your
code is equivocal on the issue. My best guess is that you are very close to
"getting it". But if I guess wrong on this, I end up wasting time for both
of us don't I?) Accordingly, I've tried to set you in the right direction
and then let you figure it out. :-)
One thing I sometimes suggest to beginners is that they work without using
xsl:for-each. (I use it, but it's really just syntax sugar: given that you
can use "mode" on any template rule or apply-templates instruction, you
don't really need for-each at all.) Maybe you should try rewriting your
stylesheet to work exactly the same, but without using for-each anywhere.
xsl:for-each is kind of like training wheels on a bike: they can be
reassuring if you think you're going to lose your balance. But you're not
really riding a bike until you don't need them.
Use "mode" instead. Research XSLT modes if you're not sure how they work.
(And after you've written a few too many extra modes, you may want to come
back to for-each for some things.)
Good luck,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================