|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
setting xsl parameter from dropdown menu
What i want to be able to do is the user selects a date from the drop down menu, the form selects a value, which will change the value in the xsl
aram statement below to whatever is selected<xsl aram name="votedate">07/03/04</xsl aram<form name="exampleForm"> <select name="exampleSelect"> <option value="15/02/04">15/02/04</option> <option value="22/02/04">22/02/04</option> <option value="29/02/04">29/02/04</option> </select> <input type="submit" value="Submit" onclick="doAlert()" /> </form> <xsl:for-each select="//A[VOTEDATE=$votedate]"> <xsl:sort select="VOTES" data-type="number" order="descending"/> I just can't seem to get it working. The actual page can be found here: http://www.gre.ac.uk/~tk301/3dmm/results.html |
|
#2
|
|||
|
|||
|
anyone?
|
|
#3
|
||||
|
||||
|
the only solution i know of is to use some server-side page to print out the xsl data with the text/xsl content-type header and dynamically create the parameter...
|
|
#4
|
|||
|
|||
|
Solution
Yep i found out the solution,
<table cellpadding="0" cellspacing="0" border="0" bgcolor="white" width="100%" align="center"><tr><td> <div id="target"></div> <SCRIPT LANGUAGE="JavaScript"> function doTransform(){ var objXSLT = new ActiveXObject("MSXML2.FreeThreadedDomDocument"); objXSLT.async = false; objXSLT.load("data/votestylesheet.xsl"); var objCompiled = new ActiveXObject("MSXML2.XSLTemplate"); objCompiled.stylesheet = objXSLT.documentElement; var objXSLProc = objCompiled.createProcessor(); var objXML = new ActiveXObject("MSXML2.FreeThreadedDomDocument"); objXML.preserveWhiteSpace = true; objXML.async = false; objXML.load("data/votes2004.xml"); objXSLProc.input = objXML; objXSLProc.addParameter("votedate", voteDate + ""); objXSLProc.transform(); target.innerHTML = objXSLProc.output; } </SCRIPT></table> in the html page and then <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl utput method="html" encoding="UTF-8"/><xsl:key name="kDate" match="*[VOTEDATE]" use="VOTEDATE"/> <xsl aram name="votedate" select="//*[VOTEDATE]"/><xsl:template match="/"> <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center"> <tr> <td rowspan="2" valign="top" align="center" width="175"> <form name="exampleForm"> <select name="exampleSelect" onchange="changeVoteDate(this.value)"> <option value="" selected="selected">Select A Date</option> <option value="">Show All</option> <xsl:for-each select="/MOVIES/*[generate-id() = generate-id(key('kDate', VOTEDATE))]"> <option value="{VOTEDATE}"> <xsl:value-of select="VOTEDATE"/> </option> </xsl:for-each> </select> </form> </td> <td valign="bottom"><font face="verdana" size="1" color="black"> <b>Date:</b> *<xsl:value-of select="$votedate"/> </font></td></tr> <tr><td valign="top"><font face="verdana" size="1" color="black"> <b>Total Votes:</b> *<xsl:value-of select="sum(//A[VOTEDATE= $votedate]/VOTES)"/> </font> </td></tr> </table> <table cellpadding="0" cellspacing="0" border="0" width="500" align="center"> <xsl:choose> <xsl:when test="$votedate != ''"> <xsl:apply-templates select="MOVIES/*[VOTEDATE = $votedate]"> <xsl:sort select="VOTES" data-type="number" order="descending"/> </xsl:apply-templates> </xsl:when> <xsl therwise><xsl:apply-templates select="MOVIES/*[VOTEDATE]"> <xsl:sort select="MOVIENAME" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl therwise></xsl:choose> </table> </xsl:template> <xsl:template match="*[VOTEDATE]"> <tr class="blue"> <td align="left" valign="top" width="200"><font face="verdana" size="1" color="#F7F7F7"> <xsl:attribute name="id"><xsl:value-of select="MOVIENAME"/></xsl:attribute> <xsl:element name="a"><xsl:attribute name="href">search.html?searchCriteria=<xsl:value-of select="MOVIENAME"/>&searchField=MOVIENAME </xsl:attribute><xsl:value-of select="MOVIENAME"/></xsl:element></font></td> <td align="center" valign="top" width="60"><font face="verdana" size="1" color="black"> (<xsl:value-of select="RELEASEDATE"/>)</font></td> <td align="left" valign="top" width="100"> <img border="0" alt="Results"> <xsl:attribute name="src">images/pollendleft.jpg</xsl:attribute> <xsl:attribute name="height">10</xsl:attribute> <xsl:attribute name="width">4</xsl:attribute> </img> <img border="0" alt="Results"> <xsl:attribute name="src">images/poll.jpg</xsl:attribute> <xsl:attribute name="height">10</xsl:attribute> <xsl:attribute name="width"> <xsl:variable name="totalMovies" select="sum(//A[VOTEDATE = $votedate]/VOTES)"/> <xsl:variable name="countVotes"> <xsl:value-of select="VOTES"/></xsl:variable> <xsl:variable name="totalPercent"> <xsl:value-of select="$countVotes div $totalMovies"/></xsl:variable> <xsl:value-of select="$totalPercent * 100"/> </xsl:attribute> </img> <img border="0" alt="Results"> <xsl:attribute name="src">images/pollendright.jpg</xsl:attribute> <xsl:attribute name="height">10</xsl:attribute> <xsl:attribute name="width">4</xsl:attribute> </img> </td> <td align="left" valign="top" width="5"><font face="verdana" size="1" color="black"> <xsl:variable name="totalVotes" select="sum(//A[VOTEDATE = $votedate]/VOTES)"/> <xsl:variable name="countVotes"><xsl:value-of select="VOTES"/></xsl:variable> <xsl:variable name="totalPercent"> <xsl:value-of select="$countVotes div $totalVotes"/></xsl:variable> <xsl:value-of select="round($totalPercent * 100)"/>%</font></td> </tr> </xsl:template> </xsl:stylesheet> that is the stylesheet that sets the parameter from a drop down list |
|
#5
|
|||
|
|||
|
Does that work cross-browser? Looks like you're only coding for the MSIE world. How does Moz, Opera, and Netscape work with your code?
|
|
#6
|
||||
|
||||
|
exactly my point...which is why i said "server-side", not client-side.
anyways, i do believe there is some sorta xml document loading object for moz...i found it earlier...im just having trouble relocating it.. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > setting xsl parameter from dropdown menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|