[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: retrieve data from #1 xml via data from #2 xml

Subject: Re: Re: retrieve data from #1 xml via data from #2 xml (again)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 14 Apr 2001 17:50:07 +0100
Re:  Re: retrieve data from #1 xml via data from #2 xml
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.