|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I'm using asp to take user input from a form and set variables in an xsl doc. I want to be able to use a variable with xsl:key, eg:
<xsl:key name="searchKey1" match="project" use="$searchBy1" /> But because it's a match, not a select, expression, I can't. I could get round this manually - and set up a key for each search category. But the whole point with what I'm building is that the search categories are derived from an xml document which can be added to/changed etc. over time. ie: To add a new category you don't have to go back into the xsl code. Is there a way round this? I've scratched my head a lot and really can't work out what to do, so any help would be much apprieciated. Here's the relevant files: a) sample from the xml doc: <data> <project> <name>Community Enablers - Fulham Court</name> <no>0304_1_1</no> <finYear>0304</finYear> <year>03</year> <month>05</month> <borough>Hammersmith and Fulham</borough> <subArea>Fulham</subArea> <theme>Communities</theme> </project> <project> <name>Monks Park</name> <no>0304_2_1</no> <finYear>0304</finYear> <year>03</year> <month>08</month> <borough>Brent</borough> <subArea>Toykington</subArea> <theme>Land</theme> </project> ... </data> b) the xsl doc: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="searchBy1">any</xsl:variable> <xsl:variable name="searchFor1">any</xsl:variable> <xsl:variable name="searchBy2">any</xsl:variable> <xsl:variable name="searchFor2">any</xsl:variable> <xsl:key name="searchKey1" match="project" use="$searchBy1" /> <xsl:key name="searchKey2" match="project" use="$searchBy2" /> <xsl:template match="/data"> <h2>Information is available on the following projects</h2> <p>Not what you're looking for? <a href="javascript:history.back()">Try another search</a></p><hr/><br/> <xsl:for-each select="key('searchKey1', $searchFor1)"> <xsl:sort select="no"/> <p id="{no}"><a href="{concat('http://westlondonhome.ground-level.org/', no, '.xml')}"><xsl:value-of select="name"/></a><hr/><br/></p> </xsl:for-each> <xsl:for-each select="key('searchKey2', $searchFor2)"> <xsl:sort select="no"/> <p id="{no}"><a href="{concat('http://westlondonhome.ground-level.org/', no, '.xml')}"> <xsl:value-of select="name"/></a><hr/><br/></p> </xsl:for-each> </xsl:template> </xsl:stylesheet> c) For what it's worth here's the asp file: (setting variables may look clumsy - I'm new to this and couldn't for the life of me get the addParameter method to work) <% var xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("stylesheet.xsl")) var xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("projectSearchData.xml")) sBy1 = Request.Form("searchBy1") sFor1 = Request.Form("searchFor1") sBy2 = Request.Form("searchBy2") sFor2 = Request.Form("searchFor2") root=xsl.documentElement a=root.firstChild.firstChild var newTxt1 = xsl.createTextNode(sBy1) a.removeChild(a.firstChild) a.appendChild(newTxt1) b=root.firstChild.secondChild var newTxt2 = xsl.createTextNode(sFor1) b.removeChild(b.firstChild) b.appendChild(newTxt2) c=root.firstChild.thirdChild var newTxt3 = xsl.createTextNode(sBy2) c.removeChild(c.firstChild) c.appendChild(newTxt3) d=root.firstChild.fourthChild var newTxt4 = xsl.createTextNode(sFor2) d.removeChild(d.firstChild) d.appendChild(newTxt4) Response.Write(xml.transformNode(xsl)) %> Thanks in advance, james. |
|
#2
|
|||
|
|||
|
cheers - just picked this up - yours is the route I've gone down...
j |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > xsl:key match expression doesn't support variables - any way round? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|