XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
robert wakefordSubject: group items for output in a table (xsl)
Author: robert wakeford
Date: 20 Mar 2007 07:17 AM
Originally Posted: 20 Mar 2007 05:10 AM
Hi. I'm a complete newb to xsl and this is my first project after having done all the standard tutorials available on the web.

What I'm trying to do is format output from the NOAA weather webservice.

All I'm trying to do is create (what I perceived to be) a simple table of daily maximum and minimum temperatures.

http://www.lonely-camel.co.uk/components/com_weather/weather.xml

My desired output would be a three col table as follows:

from the nodes: -

dwml/data/parameters/temperature/@type="maximum"

dwml/data/parameters/temperature/@type="minimum"

dwml/data/time-layout/@summarization="24hourly"

<table>
<tr>
<th>Date </th>
<th>Daily Maximum Temp (name tag)</th>
<th>Daily Minimum Temp (name tag)</th>
<tr>
<td>start date (start-valid-time tag)</td>
<td>min temp (value tag)</td>
<td>max temp (value tag)</td>
</tr>
<tr>
<td>min temp (value tag)</td>
<td>max temp (value tag)</td>
</tr>
<tr>
<td>min temp (value tag)</td>
<td>max temp (value tag)</td>
</tr>
<tr>
<td>min temp (value tag)</td>
<td>max temp (value tag)</td>
</tr>
etc..
</table>


Unfortunately all the examples I had in the tutorials had much simpler data formats where I could easily loop through the data.

I've just installed the demo of stylus studio (which seems brilliant) but even with this powerful tool I cannot see a way to format the data in the way that I want.

All help greatfully received.

Regards,

Rob


Unknownweather.xml
xml file generated by the NOAA webserv

Postnext
(Deleted User) Subject: group items for output in a table (xsl)
Author: (Deleted User)
Date: 20 Mar 2007 10:56 AM
Hi Robert,
I came up with this solution: it's kind of hardcoded in the sense that always has two columns (instead of displaying one per <temperature> node), but at least shows you how you can correlate the <value> nodes belonging to different parents.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html"/>

<xsl:template match="/">
<table border="1">
<tr>
<th><xsl:value-of select="dwml/data/parameters/temperature[@type='minimum']/name"/></th>
<th><xsl:value-of select="dwml/data/parameters/temperature[@type='maximum']/name"/></th>
</tr>
<xsl:for-each select="dwml/data/parameters/temperature[@type='minimum']/value">
<xsl:variable name="offset" select="count(preceding-sibling::value)"/>
<xsl:variable name="min" select="."/>
<xsl:variable name="max" select="../../temperature[@type='maximum']/value[$offset+1]"/>
<tr>
<td>
<xsl:if test="$min/@xsi:nil">N/A</xsl:if>
<xsl:if test="not($min/@xsi:nil)"><xsl:value-of select="$min"/></xsl:if>
</td>
<td>
<xsl:if test="$max/@xsi:nil">N/A</xsl:if>
<xsl:if test="not($max/@xsi:nil)"><xsl:value-of select="$max"/></xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>

Alberto

Postnext
robert wakefordSubject: group items for output in a table (xsl)
Author: robert wakeford
Date: 20 Mar 2007 11:10 AM
Many thanks Alberto.

I've had a brief look at you solution and I've already spotted quite a few pointers. I'll have a more indepth look this evening. Many thanks for coming back to me.

Postnext
robert wakefordSubject: group items for output in a table (xsl)
Author: robert wakeford
Date: 22 Mar 2007 04:27 AM
many thanks alberto. Probably a silly question but you seem to reference two name spaces. is this a typo? xsi and xsl

Regards,

Rob

Postnext
(Deleted User) Subject: Re: group items for output in a table (xsl)
Author: (Deleted User)
Date: 22 Mar 2007 04:35 AM
Hi Robert,
no, it's not a typo: xsl is needed to express the XSLT instructions,
and xsi is needed to reference the xsi:nil attribute in the XPath expressions.

Alberto

Postnext
robert wakefordSubject: Re: group items for output in a table (xsl)
Author: robert wakeford
Date: 22 Mar 2007 05:10 AM
Many thanks I'll continue with my studies!

I'm determined to get a handle on this because xsl appears to be so much cleaner to use than writing endless lines of Javascript or php code. Its also would appear that it will be much quicker to develop applications than using the other methodolgies.

Postnext
robert wakefordSubject: Re: group items for output in a table (xsl)
Author: robert wakeford
Date: 23 Mar 2007 07:34 PM
Originally Posted: 23 Mar 2007 07:19 PM
Hi Alberto,

Thanks for your help. I've made lots of progress but I've run into a problem that I can't find a solution for.

If you look at the xml snippet below you will notice that some (but not all) of the weather-conditions tags have a child node callled <value>

My problem is that at the moment I only seem to be able to diplay the first occurance of the value node.

Please find attached a copy of my current xsl and a dump of the xml feed from the noaa webservice.

<weather time-layout="k-p24h-n7-1">
<name>Weather Type, Coverage, and Intensity</name>
<weather-conditions weather-summary="Rain">
<value coverage="definitely" intensity="light" weather-type="rain" qualifier="none">
</value>
</weather-conditions>
<weather-conditions weather-summary="Chance Rain">
<value coverage="chance" intensity="light" weather-type="rain" qualifier="none">

</value>
</weather-conditions>
<weather-conditions weather-summary="Mostly Sunny">
</weather-conditions>
<weather-conditions weather-summary="Mostly Sunny">
</weather-conditions>
<weather-conditions weather-summary="Chance Rain Showers">
<value coverage="chance" intensity="light" weather-type="rain showers" qualifier="none">
</value>

</weather-conditions>
<weather-conditions weather-summary="Partly Cloudy">
</weather-conditions>
<weather-conditions weather-summary="Partly Cloudy">
</weather-conditions>
</weather>

Link to webservice request form. - Its pre-seeded so just hit submit

http://www.lonely-camel.co.uk/components/com_weather/ndfdSOAPByDay.htm

Kind Regards,

Rob


Unknownweather(1).xml


Unknownxslstylesheet(2).xsl

Postnext
(Deleted User) Subject: Re: group items for output in a table (xsl)
Author: (Deleted User)
Date: 26 Mar 2007 11:32 AM
Hi Robert,
double check this line

<xsl:variable name="intensity" select="../../weather/weather-conditions/value[$offset+1]/@intensity"/>

You are applying the $offset to the 'value' node, instead of the 'weather-conditions', and I think this is not what you want....

Alberto

Posttop
robert wakefordSubject: Re: group items for output in a table (xsl)
Author: robert wakeford
Date: 27 Mar 2007 04:40 AM
SUCCESS!

Thank you very, very much Alberto!

I will now try and complete this exercise in XSL.

I will post back here when its completed (assuming I don't encounter any further problems :)) so that you can see the final results, so please keep monitoring the thread.

Many thanks once again!

Rob

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.