Re: [xsl] Re: retrieve data from #1 xml via data from #2 xml (again)

Subject: Re: [xsl] Re: retrieve data from #1 xml via data from #2 xml (again)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 11 Apr 2001 18:33:37 +0100
Hi Walter,

> But, this should only give me 3 rows of data, since that is all I am giving
> it.
>
> Instead, I get my 3 rows of data, 3 times.
>
> I justed added a forth row, now I get 4 copies of the 4 rows.

I tried it with this template:

<xsl:template match="/">
   <table>
      <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>
   </table>
</xsl:template>

With the data you've provided before, the variable definitions you've
provided before and the display data that you've provided before.

I got this output:

<table>
   <tr>
      <td/>
      <td>Vincent</td>
      <td/>
      <td>Case Resolution</td>
      <td>test</td>
   </tr>
   <tr>
      <td/>
      <td>Vincent</td>
      <td/>
      <td>Case Resolution</td>
      <td>testing 10:10 AM</td>
   </tr>
   <tr>
      <td/>
      <td>Vincent</td>
      <td/>
      <td>Case Resolution</td>
      <td>test 10:30am</td>
   </tr>
</table>

Three interaction elements, three rows. As a wild stab in the dark, I
suspect that somewhere you're doing something like:

   <xsl:apply-templates select="$data" />

and that you then have a template that matches each interaction
element, and have the xsl:for-each within it:

<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>

This is telling the processor to process each of the interaction
elements using the relevant template, and then telling it for each of
those interaction elements to go through each of the interaction
elements, and produce a row for each.  If you want to apply templates
and place the stuff producing the row for an interaction within the
template, then you don't need the xsl:for-each:

<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>

Anyway, that's a complete guess - if you post your stylesheet then it
would be a lot easier to debug it for you.

I hope that helps anyway,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread