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

Re: Tieing elements and corresponding child elements

Subject: Re: Tieing elements and corresponding child elements together.
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 1 Nov 2007 11:05:38 +0000
Re:  Tieing elements and corresponding child elements
On 01/11/2007, Glen Mazza <glen.mazza@xxxxxxxxx> wrote:
> Hello, the XML below is a sharply simplified version of Memphis weather
> data available from the National Weather Service's SOAP web service[1].
>
> <dwml version="1.0">
>   <data>
>     <time-layout time-coordinate="local" summarization="none">
>       <layout-key>k-p24h-n7-1</layout-key>
>       <start-valid-time period-name="Tomorrow"/>   <!-- Thursday -->
>       <start-valid-time period-name="Friday"/>
>       <start-valid-time period-name="Saturday"/>
>       <start-valid-time period-name="Sunday"/>
>       <start-valid-time period-name="Monday"/>
>       <start-valid-time period-name="Tuesday"/>
>       <start-valid-time period-name="Wednesday"/>
>     </time-layout>
>     <time-layout time-coordinate="local" summarization="none">
>       <layout-key>k-p24h-n7-2</layout-key>
>       <start-valid-time period-name="Tonight"/>   <--- Wed. night -->
>       <start-valid-time period-name="Tomorrow Night/>
>       <start-valid-time period-name="Friday Night"/>
>       <start-valid-time period-name="Saturday Night"/>
>       <start-valid-time period-name="Sunday Night"/>
>       <start-valid-time period-name="Monday Night"/>
>       <start-valid-time period-name="Tuesday Night"/>
>     </time-layout>
>     <parameters applicable-location="point1">
>       <temperature type="maximum" units="Fahrenheit"
> time-layout="k-p24h-n7-1">
>         <name>Daily Maximum Temperature</name>
>         <value>65</value>
>         <value>66</value>
>         <value>68</value>
>         <value>71</value>
>         <value>72</value>
>         <value>63</value>
>         <value>60</value>
>       </temperature>
>       <temperature type="minimum" units="Fahrenheit"
> time-layout="k-p24h-n7-2">
>         <name>Daily Minimum Temperature</name>
>         <value>55</value>
>         <value>44</value>
>         <value>44</value>
>         <value>46</value>
>         <value>50</value>
>         <value>49</value>
>         <value>41</value>
>       </temperature>
>      </parameters>
>   </data>
> </dwml>
>
>
> With this data, I would like to create a simple listing as follows:
>
> Daily Maximum Temperatures:
> -----------------------
> Tomorrow: 65
> Friday: 66
> Saturday: 68
> ...
>
> Daily Minimum Temperatures:
> ------------------------
> Tonight: 55
> Tomorrow Night: 44
> Friday Night: 44
> ...
>
> Note that, in the XML data, the blocks of time-layouts are tied to the
> Max. and Min. temps below via the layout-key element / time-layout
> attribute combination.
>
> I guess my questions are
> (1) how can I tie the time-layout elements and temperature elements
> together using XSLT 1.0 using the layout-key

Either do it using =, or just use a key:

<xsl:key name="temperature-by-time-layout" match="temperature"
use="@time-layout"/>

with:

key('temperature-by-time-layout", layout-key)

(when the context node is <time-layout>)


> (2) how can I tie each period-name to its corresponding position with
> the temperatures that it is associated with

use position()

> In other words, how can I create my table above?

It's poor quality XML really to rely on position of elements to match
them up, but it's perfectly possible and straightforward to do what
you need with XSLT 1.0.


cheers
-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

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.