Hi
I am new to XML programming (1 week) and need to get this working ASAP. PLEASE ASSIST URGENTLY. My javascript code does not dynamically pass parameters to the xsl file. If I hard code the parameters, everything works. but when I try to access the parameters from dynamically, the parameters remain blank. HEEEELP
My code is below.
XML file (xml2.xml)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="./test2.xsl"?>
<CATALOG>
<GENRE GENRENAME="POP">
<CD PRODUCT="BONDS">
<TRADER>
<TITLE>zEmpire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</TRADER>
</CD>
<CD PRODUCT="FRA">
<TRADER>
<TITLE>Soweto</TITLE>
<ARTIST>Mandoza</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>MTN</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
<TRADER>
<TITLE>2JAzzSoweto</TITLE>
<ARTIST>2Mandoza</ARTIST>
<COUNTRY>2USA2</COUNTRY>
<COMPANY>2MTN</COMPANY>
<PRICE>210.902</PRICE>
<YEAR>219852</YEAR>
</TRADER>
</CD>
<CD PRODUCT="SWAPS">
<TRADER>
<TITLE>Poland</TITLE>
<ARTIST>Bob Dylan2</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>Columbia2</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
</CD>
<CD PRODUCT="TBILLS">
<TRADER>
<TITLE>South Africa</TITLE>
<ARTIST>TTT</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>VODAFONE</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
</CD>
</GENRE>
<GENRE GENRENAME="JAZZ">
<CD PRODUCT="BONDS">
<TRADER>
<TITLE>JAzzEmpire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</TRADER>
</CD>
<CD PRODUCT="FRA">
<TRADER>
<TITLE>JAzzSoweto</TITLE>
<ARTIST>Mandoza</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>MTN</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
<TRADER>
<TITLE>2JAzzSoweto</TITLE>
<ARTIST>2Mandoza</ARTIST>
<COUNTRY>2USA2</COUNTRY>
<COMPANY>2MTN</COMPANY>
<PRICE>210.902</PRICE>
<YEAR>219852</YEAR>
</TRADER>
</CD>
<CD PRODUCT="SWAPS">
<TRADER>
<TITLE>JAzz</TITLE>
<ARTIST>Bob Dylan2</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>Columbia2</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
</CD>
<CD PRODUCT="TBILLS">
<TRADER>
<TITLE>JAzzSouth Africa</TITLE>
<ARTIST>TTT</ARTIST>
<COUNTRY>USA2</COUNTRY>
<COMPANY>VODAFONE</COMPANY>
<PRICE>10.902</PRICE>
<YEAR>19852</YEAR>
</TRADER>
</CD>
</GENRE>
</CATALOG>
XSL file (test2.xsl)
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="genre"/>
<xsl:param name="prodName"/>
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@* | * | comment() | processing-instruction() | text()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<script language="javaScript" src="submit.
js"/>
</head>
<body>
<form name="frm">
<!--xsl:choose>
<xsl:when test="$genre='JAZZ'">
<xsl:apply-templates mode="submit" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$genre"/>
</xsl:otherwise>
</xsl:choose-->
<Table>
<TR>
<TD>SELECT TYPE</TD>
<TD>
<select name ="genre" onChange="submit('name')" id="select1">
<option>ALL</option>
<xsl:apply-templates select="CATALOG"/>
</select>
</TD>
</TR>
<TR>
<TD>SELECT CD</TD>
<TD>
<select name ="prodName" onChange="javaScript
:submit(this)" id="select2">
<option>ALL CDs</option>
<xsl:choose>
<xsl:when test="$genre='JAZZ'">
<xsl:choose>
<xsl:when test="CATALOG/GENRE[@GENRENAME=$genre]">
<option>Found</option>
<xsl:for-each select="CATALOG/GENRE[@GENRENAME=$genre]/CD">
<option value="{@PRODUCT}">
<xsl:attribute name = "value"><xsl:value-of select="@PRODUCT"/></xsl:attribute>
<xsl:value-of select="@PRODUCT"/>
</option>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<option> <xsl:value-of select="$genre" /> </option>
<option> <xsl:value-of select="." /> </option>
<option> not found </option>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<option>Jazz not selected</option>
<option><xsl:value-of select="$genre"/></option>
</xsl:otherwise>
</xsl:choose>
</select>
</TD>
</TR>
</Table>
<xsl:call-template name="DisplayTraderList">
<xsl:with-param name="ARTIST">TTT</xsl:with-param>
</xsl:call-template>
</form>
</body>
</html>
</xsl:template>
<xsl:template match="CATALOG">
<xsl:for-each select="GENRE">
<option value="{@GENRENAME}">
<xsl:attribute name = "value"><xsl:value-of select="@GENRENAME"/></xsl:attribute>
<xsl:value-of select="@GENRENAME"/>
</option>
</xsl:for-each>
</xsl:template>
<xsl:template match="CATALOG/GENRE">
<xsl:for-each select="CD">
<option value="{TITLE}">
<xsl:attribute name = "value"><xsl:value-of select="TITLE"/></xsl:attribute>
<xsl:value-of select="TITLE"/>
</option>
</xsl:for-each>
</xsl:template>
<xsl:template name="DisplayTraderList" match="CATALOG/GENRE/CD">
<xsl:param name="ARTIST" />
<table border="2" bgcolor="grey" visible="true">
<tr>
<th>Trader name</th>
<th>Tel</th>
<th>Reuters code</th>
<th>Location</th>
</tr>
<xsl:for-each select="CATALOG/GENRE[@GENRENAME=$genre]/CD[@PRODUCT=$prodName]/TRADER">
<tr>
<td><xsl:value-of select="ARTIST" /></td>
<td><xsl:value-of select="TITLE" /></td>
<td><xsl:value-of select="COMPANY" /></td>
<td><xsl:value-of select="YEAR" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="CATALOG" mode="submit">
<table width="80%" bgcolor="#FF8800">
<tr><td>
<xsl:value-of select="$genre"/>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
javascript file(submit.
js)
function submit(obj){
try{
var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
var x = document.XMLDocument;
if (x == null){
x = navigator.XMLDocument;
s.loadXML(navigator.XSLDocument.xml);
}else{
s.loadXML(document.XSLDocument.xml);
}
var tem = new ActiveXObject("MSXML2.XSLTemplate");
tem.stylesheet = s;
var proc = tem.createProcessor();
//proc.addParameter("genre",frm.genre.options[frm.genre.selectedIndex].value);
//proc.addParameter("prodName",frm.prodName.options[frm.prodName.selectedIndex].value);
proc.addParameter("genre",'JAZZ');
proc.addParameter("prodName",'FRA');
proc.input = x;
proc.transform();
var str = proc.output;
var newDoc = document.open("text/html");
newDoc.write(str);
navigator.XMLDocument = x;
navigator.XSLDocument = s;
newDoc.close();
}catch(exception){
}
}