This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: retrieve data from #1 xml via data from #2 xml (again)
Hi Walter,
> OK, here is my XSLT file.
Thanks. This shows that my guess was miraculously close. I'll try to
explain it again...
You have a template that matches an interaction_list. Within that
template, you have an xsl:apply-templates instruction:
<xsl:template match='callEvent/response/interaction_list'>
...
<!-- This will loop for each Interaction in this data stream -->
<!-- This calls the ROOT NODE Template below -->
<xsl:apply-templates />
...
</xsl:template>
(Those are your comments, BTW.)
Now, when you use xsl:apply-templates without a select attribute, the
XSLT processor will apply templates to all the child nodes of the
current node. In the context of this template, the current node is an
interaction_list element. The children of the interaction_list element
include a number of interaction elements. So templates are applied to
those interaction elements (3 of them). The processor finds the
template to match interaction elements, this one:
<xsl:template match='interaction'>
<xsl:for-each select="$data">
<tr>
<xsl:variable name="datum" select="events/call_event" />
<xsl:for-each select="$columns">
<xsl:variable name="column" select="." />
<td>
<xsl:value-of select="$datum/*[name() = $column]" />
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
In this template, the xsl:for-each tells the processor to iterate over
a number of nodes - the interaction elements held by the $data
variable. So your stylesheet runs this template three times, and the
content of the xsl:for-each is run three times as well. Or if you have
four interaction elements, then the template is run four times; and
the xsl:for-each runs the instructions it contains four times.
So essentially you're doing the iteration over twice, once through
applying templates to the interaction elements; once by iterating over
them with an xsl:for-each.
To solve the problem, just remove the xsl:for-each to make it:
<xsl:template match='interaction'>
<tr>
<xsl:variable name="datum" select="events/call_event" />
<xsl:for-each select="$columns">
<xsl:variable name="column" select="." />
<td>
<xsl:value-of select="$datum/*[name() = $column]" />
</td>
</xsl:for-each>
</tr>
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list