Jump to content
Sign in to follow this  
prichardson

Retriving Property By Property Id - Example Property 3624

Recommended Posts

Hi,I've got website that runs fine by displaying all the properties from a 3rd party xml data. I want to now just list the individual property that matches the property id. My problem is that when i try to get it to appear like this - i dont get any result. (funny enough if i changed it from property id to lets say number of beds - it works, so i'm a little bit confused.This first bit of code is a snippet of my classic asp cod e page that connects and sends over the url...

<%strSearch = 3624Set xmldoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")xmldoc.async = falsexmlDoc.setProperty "ServerHTTPRequest", trueURL = "http://web.aspasia.net/pls/oliverfn/aspasia_search.xml?upw=XXXXXXXXXXXXXXXXXXXXX&pp=1&pr=3624"xmldoc.load(URL)Set xsldoc =  Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")xsldoc.async = falsexsldoc.load(Server.MapPath("property.xsl"))Set Node = xmldoc.selectSingleNode("aspasia_data/houses/property")Set template=Server.CreateObject("MSXML2.XSLTemplate")template.stylesheet=xsldocSet processor=template.createProcessorprocessor.input = xmldocIf strSearch = "" Thenprocessor.addParameter "Search", "" & strSearch & ""End Ifprocessor.transform()Response.write  (processor.output)%>

This second bit is the first part of the XSLT code that displays the property...(my question here might be about the template match - i tried 'id' and also the path to the id)?

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:param name="Search"/>	<xsl:template match="/">	<xsl:choose>		<xsl:when test="aspasia_data/houses/property/address/property_location">			<xsl:for-each select="aspasia_data/houses/property"> 				<xsl:sort order="descending" select="aspasia_data/houses/property"/>												 <xsl:value-of select="address/property_location"/>

.......This 3rd bit is the snippet of the actual xml from the third party -you can see the tags...

- <aspasia_data>		  − <houses>					 −<property id="3624" prevref="062" last_updated="03/04/2009 16:03" created_date="11/04/2008 16:28">						  <id>3624</id>												  − <address>													   <address1>7a Priory Road</address1>													   <town>Chiswick</town>													   <property_location>Chiswick</property_location>													</address>

My Question i think is the any reason why my code is not actually able to pull the property result by using the property ID??I appreciate your help as i just can't see what my problem is.Many Thanks

Share this post


Link to post
Share on other sites

You said if you use another thing, such as the number of beds, it works. Where exactly is this data? Is it on the same level as the ID and in an element? For example:

 <aspasia_data>		   <houses>					 <property id="3624" prevref="062" last_updated="03/04/2009 16:03" created_date="11/04/2008 16:28">						  <id>3624</id>												   <address>													   <address1>7a Priory Road</address1>													   <town>Chiswick</town>													   <property_location>Chiswick</property_location>													</address>						  <number_of_beds>3</number_of_beds>

?If it works with THAT, just renaming "number_of_beds" to "id" should work.Otherwise, try:

			<xsl:for-each select="aspasia_data/houses/property[@id=$Search]">

Share this post


Link to post
Share on other sites

Hi,LATEST UPDATE:I've tried branch and a couple others that are on the same path and they work ok! It's just not working when i put the ID in. If the code is correct as it pulls in anything else and I've got your piece of code in that you suggested. What could it be?----------------------------------------------------------------------------------------------------------------------------------The number of beds - you can see it's the last item in the code snippet (might not be very clear, sorry). It lies in 1 additional layer to the id. i.e. ...The path for the id = aspasia_data/houses/property/idThe path for beds = aspasia_data/houses/property/address/number_of_bedsIt might be the path issue as you say - it should work otherwise - that is why i'm so confused! lolI tried that bit of code you suggested, but i still don't get the result. I can see that - that the piece of the code should make it work... so it must be something before that code or like you said maybe the paths - which i've doubled checked.A quick few questions - I don't need to change the 'match' from '/' to 'id' or the path to the id... i.e. it should still be '/'?-This line <xsl:when test="aspasia_data/houses/property/address/property_location"> should that be this instead <xsl:when test="aspasia_data/houses/property/id> ?-is there a way of testing/writing out the url to see if it passes through the parmeter etc. ?- is this is correct in the asp page (the path?) - Set Node = xmldoc.selectSingleNode("aspasia_data/houses/property") Any other suggestions?Much appreciated as always.

Edited by prichardson

Share this post


Link to post
Share on other sites

The sample you're showing isn't unclear about number_of_beds... it doesn't have number_of_beds at all :) .ID appears to be present at two places - an attribute (aspasia_data/houses/property/@id) and an element (aspasia_data/houses/property/id).If number_of_beds is at aspasia_data/houses/property/address/number_of_beds, then your sample should be:

<aspasia_data>		   <houses>					 <property id="3624" prevref="062" last_updated="03/04/2009 16:03" created_date="11/04/2008 16:28">						  <id>3624</id>												   <address>													   <address1>7a Priory Road</address1>													   <town>Chiswick</town>													   <property_location>Chiswick</property_location>													   <number_of_beds>3</number_of_beds>													</address>

correct?Anyhow, you can print the parameter with xsl:value-of, like:

	<xsl:template match="/"><xsl:value-of select="$Search" />

You don't need to replace the match with anything, but you may swich to using several templates, and there are some benefits if you do (performance and maintainance wise) if you do. However, it's a big undertaking. If the part of the XSLT you're showing is part of a much bigger and complex stylesheet, it will be very hard to switch to a template based workflow.Both "aspasia_data/houses/property/address/property_location" and "aspasia_data/houses/property/id" are valid conditions. Both are true if there's an element at that path. But seriously, you don't need them. A for-each with the same select will process only elements matching that path. If there are no such element, it won't process anything. If you want to process only property elements that have an "address/property_location" element, you can use a predicate, like so:

<xsl:for-each select="aspasia_data/houses/property[address/property_location]">

The path "aspasia_data/houses/property" will select all property elements, and return them as a DOMNodeList (or something similar... I don't know ASP). If this is what you want, it's all OK. If you want to be extra safe, you may add a "/" at the start of the path to make sure it's absolute, relative to the root node. BTW, your current code (or at least the part that you show) doesn't do anything with the results from this.I'm not sure I can suggest much else, as what you have appears to be a little messy. If you aren't sure how/if parameters are passed and processed in XSLT (and/or ASP), take a step back, and test just that with a separate, non related stylesheet. Then consider what you want to do, and create a new, template based stylesheet. That is, instead of using a lot of for-each constructs, consider having:

<xsl:template match="/"><!-- Everything that appears on every page at the top. e.g. <html><head>...</head><body><div id="nav">...--><xsl:apply-templates/><!-- Everything that appears on every page at the botton. e.g. <div id="footer">...</div></body></html>--></xsl:template><xsl:template match="property"><!--Everything that appears for every property --></xsl:template>

There's a little more to it than just that, especially for your case, but that's pretty much the start of it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...