XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 11th, 2003, 11:52 AM
knew_b knew_b is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: london
Posts: 4 knew_b User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question xsl:key match expression doesn't support variables - any way round?

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.

Reply With Quote
  #2  
Old June 2nd, 2003, 02:10 PM
knew_b knew_b is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: london
Posts: 4 knew_b User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
cheers - just picked this up - yours is the route I've gone down...

j

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > xsl:key match expression doesn't support variables - any way round?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway