Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Tieing elements and corresponding child elements together.

From: "Andrew Welch" <andrew.j.welch@--------->
To:
Date: 11/1/2007 11:07:00 AM
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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent