XSL, Javascript

Subject: XSL, Javascript
From: "Maulik Modi" <mxmodi@xxxxxxxxxxxxxxx>
Date: Mon, 31 Jul 2000 08:46:45 -0500

Hi XSL-List

I am trying to create tables on the fly with XSL and Javascript. Here is my XML
code as follows:

<?xml-stylesheet type="text/xsl" href="GTWeatherDemo-mm.xsl"?>
<GLUE_RTXML>
     <EVENT id="881">
          <data>
               <weather>
                    <location airportcode="yyy">
                         <weatherforecastitem>
                              <date year="2000" day="25" month="7"/>
                              <hour>2</hour>
                              <temperature>63</temperature>
                              <dewpoint>63</dewpoint>
                              <relhumidity>100</relhumidity>
                              <cloudcover>0</cloudcover>
                              <windspeed>0</windspeed>
                         </weatherforecastitem>
                    </location>
                    <location airportcode="xxx">
                         <weatherforecastitem>
                              <date year="2000" day="25" month="7"/>
                              <hour>2</hour>
                              <temperature>78</temperature>
                              <dewpoint>98</dewpoint>
                              <relhumidity>50</relhumidity>
                              <cloudcover>2</cloudcover>
                              <windspeed>5</windspeed>
                         </weatherforecastitem>
                    </location>
               </weather>
          </data>
     </EVENT>
</GLUE_RTXML>

I have a drop-down <select> box that the user can choose from. Depending on the
option selected, the table should only present that set of data in a table row.
Here is the XSL and Javascript for that (which is not working!)

XSl file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

<xsl:template match="/">
<HTML>
<HEAD>
<LINK REL="stylesheet" HREF="http://sdangel03/glueconfig/styles.css"; />
<script language="Javascript"><![CDATA[
function selbox() {

var var1= window.document.formAirPort.listAirPort;
if(var1.value == 'xxx') {

document.write('<xsl:apply-templates select=".//locationx" />');

}

if(var1.value == 'yyy') {

document.write('<xsl:apply-templates select=".//locationy" />');

}
}
 ]]></script>
 </HEAD>
<BODY>
<xsl:apply-templates select=".//GLUE_RTXML" />
</BODY>
</HTML>
</xsl:template>

<xsl:template match="GLUE_RTXML">

<center><font family="arial" size="6" color="blue" >Weather Forecast </font><br
/>

     <table border="0" cellpadding="0" cellspacing="2" width="50%">
               <tr>
                    <td align="center">
                         <table border="0" cellpadding="4" cellspacing="0"
width="90%">
                              <tr>
                                   <td align="center">Airport Code</td>
                              </tr>
                              <tr>
                                   <td align="center">

<form action="post" name="formAirPort" >
<select name="listAirPort" size="1" onchange="selbox();" >
<xsl:for-each select=".//location">
     <option>
          <xsl:attribute name="value">
               <xsl:value-of select="./@airportcode"/>
          </xsl:attribute>
          <xsl:value-of select="./@airportcode"/>
     </option>
</xsl:for-each>
</select>
</form>
</td>
                              </tr>
                         </table>
                    </td>
               </tr>
          <tr >
               <td>
                    <center>
                              <table border="1" cellpadding="0" cellspacing="0"
width="95%">
                                   <tr class="titleBar">
                                         <td align="center" valign="top">Airport
 Code</td>
                                         <td align="center"
valign="top">Date</td>
                                         <td align="center"
valign="top">Hr.</td>
                                         <td align="center"
valign="top">Temp.</td>
                                         <td align="center"
valign="top">Dewpoint</td>
                                         <td align="center" valign="top">Rel.<br
 />
                                              Humidity</td>
                                         <td align="center"
valign="top">Cloud.<br />
                                              Cover</td>
                                         <td align="center"
valign="top">Wind.<br />
                                              Speed</td>
                                   </tr>
                                   <tr>
                                         <xsl:apply-templates
select=".//location" />
                                   </tr>
                              </table>
                         </center>
                    </td>
               </tr>
          </table>


     </center>
     </xsl:template>

<xsl:template match="date">
<option><xsl:attribute name="value"><xsl:value-of
select="./@month"/>/<xsl:value-of select="./@day"/>/<xsl:value-of
select="./@year"/></xsl:attribute>
<xsl:value-of select="./@month"/>/<xsl:value-of select="./@day"/>/<xsl:value-of
select="./@year"/>
</option></xsl:template>

<xsl:template match="location">
<tr>
     <td align="center" valign="top"><xsl:value-of
select="./@airportcode"/></td>
          <td align="center" valign="top"><xsl:value-of
select="./weatherforecastitem/date/@month"/>/<xsl:value-of
select="./weatherforecastitem/date/@day"/>/<xsl:value-of
select="./weatherforecastitem/date/@year"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/hour"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/temperature"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/dewpoint"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/relhumidity"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/cloudcover"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/windspeed"/></td>
</tr>
</xsl:template>

<xsl:template match="locationy">

<tr>
     <td align="center" valign="top"><xsl:value-of
select="./@airportcode"/></td>
          <td align="center" valign="top"><xsl:value-of
select="./weatherforecastitem/date/@month"/>/<xsl:value-of
select="./weatherforecastitem/date/@day"/>/<xsl:value-of
select="./weatherforecastitem/date/@year"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/hour"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/temperature"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/dewpoint"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/relhumidity"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/cloudcover"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/windspeed"/></td>
</tr>

</xsl:template>

<xsl:template match="locationx">

<tr>
     <td align="center" valign="top"><xsl:value-of
select="./@airportcode"/></td>
          <td align="center" valign="top"><xsl:value-of
select="./weatherforecastitem/date/@month"/>/<xsl:value-of
select="./weatherforecastitem/date/@day"/>/<xsl:value-of
select="./weatherforecastitem/date/@year"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/hour"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/temperature"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/dewpoint"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/relhumidity"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/cloudcover"/></td>
                                         <td align="center"
valign="top"><xsl:value-of select="./weatherforecastitem/windspeed"/></td>
</tr>

</xsl:template>


</xsl:stylesheet>

Any help is appreciated.

Thanks.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread