Using Ajax with XSLT
Hi
I am working on a simple web application using xml, xslt and ajax.
My xml file is as follows
=====
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Hotels.xsl"?>
<Services>
<Service>
<Hotels type="radio" title="Hotel" groupname="service" default="true"/>
<HotelsFlights type="radio" title="Flight+Hotel" groupname="service"/>
</Service>
<Hotels>
<Destination title_d="Destination :">
<DestinationPlace type="OPTION" id="" title_d="Select Destination" value_d="Select Destination" defalut="true"/>
<DestinationPlace type="OPTION" id="" title_d="Aruba" value_d="Aruba" />
<DestinationPlace type="OPTION" id="" title_d="Washington" value_d="Washington" />
</Destination>
<HotelChoice title_hc="Hotels :">
<choice type="OPTION" id=" " title_h="AmsterDam Manor Beach" value_h="AmsterDam Manor Beach"/>
<choice type="OPTION" id=" " title_h="Wyndham Aruba Beach" value_h="Wyndham Aruba Beach"/>
</HotelChoice>
</Hotels>
</Services>
=========
And the xsl file as follows
======
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt" xmlns:totalSys="TotalSystem" extension-element-prefixes="totalSys">
<lxslt:component prefix="totalSys" elements="resetTotal customerInfo" functions="radioFunc">
<lxslt:script lang="javascript">
function radioFunc()
{
alert("Hai");
}
</lxslt:script>
</lxslt:component>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Services" >
<html>
<body>
<table bgcolor="lightgreen" width="350" height="200" border="1" >
<tr><td>
<xsl:apply-templates/>
</td></tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Service">
<table border="0" align="center" valign="top"><tr>
<xsl:for-each select="*">
<td align="left"><xsl:value-of select="@title"/></td>
<td align="center">
<input type="{@type}" onClick = "radioFunc()">
<xsl:attribute name="Name">
<xsl:value-of select="@groupname"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="@value"/>
</xsl:attribute>
<xsl:if test="@default='true'">
<xsl:attribute name="checked"/>
</xsl:if>
</input>
</td>
</xsl:for-each>
</tr></table><br/>
</xsl:template>
<xsl:template match="Hotels/Destination">
<xsl:value-of select="@title_d"/>
<SELECT id="dest" name="dest" onchange="showHint(this.selectedIndex);">
<xsl:for-each select="*">
<xsl:element name="{@type}">
<xsl:value-of select="@value_d"/>
</xsl:element>
</xsl:for-each>
</SELECT>
</xsl:template>
<xsl:template match="Hotels/HotelChoice">
<xsl:value-of select="@title_hc"/>
<SELECT id="hcid" name="hcid">
<xsl:for-each select="*">
<xsl:element name="{@type}">
<xsl:value-of select="@value_h"/>
</xsl:element>
</xsl:for-each>
</SELECT><br/>
</xsl:template>
</xsl:stylesheet>
=========
I have written some ajax code when there is onchange event on destination select box.From the Ajax i am getting output in xml format like
<HOTELLIST HOTELS="Renaissance,Vandetta,Viceroy">
From this i have to assign the hotels value to the hotels select box.
I am not able to write the code to assign these values to the select box specified in the xml.
regards,
raj
|