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

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

Subject: Re: retrive data from #1 xml via data from #2 xml
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Mar 2001 18:51:47 +0000
retrive data from document
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"
   select="/callEvent/response/interaction_list/interaction/events
              /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"
   select="document('DisplayData.xml')/titles/display/@id"/>

(assuming that your display data is held in a file called
DisplayData.xml)

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:

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

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:

  'source/timestamp'

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

  'ancestor::interaction/source/timestamp'

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.