Re: [xsl] retrive data from #1 xml via data from #2 xml

Subject: Re: [xsl] retrive data from #1 xml via data from #2 xml
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Mar 2001 18:51:47 +0000
Hi Walter,

> I have a piece of XSLT that I think gets close to a solution (thanks
> again Jeni), but it seems that it does not return any data.
> <tr>
>    <xsl:for-each select="$data">
>       <xsl:variable name="datum" select="." />
>       <xsl:for-each select="$columns">
>          <xsl:variable name="column" select="." />
>          <td>
>             <xsl:value-of select="$datum/*[name() = $column]" />
>          </td>
>       </xsl:for-each>
>    </xsl:for-each>
> </tr>
> [my sample data has 3 records]
> This creates a table with 3 rows, 12 columns, but no data.
> It should be 3 rows 5 columns with data.

You don't say what you've set $data and $columns to be.  You need
$data to hold the elements that you want to appear as rows.  So it
needs to be:

<xsl:variable name="data"
              /call_event" />

Of course you can crop the path there depending on the context when
you're setting the variable.

You need the $columns variable to hold nodes, each of which has a
value that is the name of the element underneath the call_event that
you want to get at.  So it needs to look something like:

<xsl:variable name="columns"

(assuming that your display data is held in a file called

That should then work, aside from the fact that one of the display
element's id attributes has a value of 'source/timestamp'. That's not
the name of any of the subelements of call_event (and it can't be
because it has a '/' in it). So I guess that you want the value of the
timestamp element of the source element in the same interaction
element as the call_event element is in.  You'll have to test
separately for that:

   <xsl:for-each select="$data">
      <xsl:variable name="datum" select="." />
      <xsl:for-each select="$columns">
         <xsl:variable name="column" select="." />
               <xsl:when test="$column = 'source/timestamp'">
                  <xsl:value-of select="ancestor::interaction/source
                                          /timestamp" />
                  <xsl:value-of select="$datum/*[name() = $column]" />

If you're going to be using strange paths a lot in your table
definitions, rather than simply using the names of the elements under
the call_event element, then you'll have to start using something like
saxon:evaluate() to evaluate the strings as XPaths.  That does mean
that you need to redefine some of it, for example rather than using:


you'd have to use the proper XPath to get from the call_event element
to the data you wanted, i.e.:


I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread