Jump to content

Spot the problem


prichardson

Recommended Posts

Hello - I am having trouble in just displaying the results which match the input Chiswick. I only want all thew Chiswick properties to appear and the rest of the properties that are not Chiswick not to appear.I believe that the problem lies in this page - Can anyone please let me know what bit of the code is wrong. I think something with the - template / param / with-param / variable

<?xml version="1.0" encoding="iso-8859-1"?><!-- DWXMLSource="properties.xml" --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" encoding="iso-8859-1"/><xsl:output method="xml" encoding="iso-8859-1"/><xsl:template name="location"><xsl:param name="Chiswick"/></xsl:template><xsl:template match="/">  <h2>Property Results:</h2>  <table width="20%" cellpadding="0" cellspacing="0" border="1">	<tr bgcolor="#9acd32">	  <th>Location</th>	  <th>Bedrooms</th>	  <th>Price</th>	</tr>	<xsl:for-each select="properties/property">	<xsl:sort select="location" order="ascending" />	<tr>	  <td>	  <xsl:variable name="Chiswick">	  <xsl:call-template name="location">	  <xsl:with-param name="Chiswick" select="location"/>	  </xsl:call-template>	  </xsl:variable>	  </td>   	  <xsl:choose>	  <xsl:when test="price > 10000">		 <td bgcolor="#ff00ff">		 <xsl:value-of select="bedrooms"/>		 </td>	  </xsl:when>	  <xsl:when test="price > 20000">		 <td bgcolor="#cccccc">		 <xsl:value-of select="bedrooms"/></td>	  </xsl:when>	  <xsl:otherwise>		 <td><xsl:value-of select="bedrooms"/></td>	  </xsl:otherwise>	  </xsl:choose>	  <td><xsl:value-of select="price"/></td>	  </tr>	</xsl:for-each>  </table></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Hello - I am having trouble in just displaying the results which match the input Chiswick. I only want all thew Chiswick properties to appear and the rest of the properties that are not Chiswick not to appear.I believe that the problem lies in this page - Can anyone please let me know what bit of the code is wrong. I think something with the - template / param / with-param / variable
<?xml version="1.0" encoding="iso-8859-1"?><!-- DWXMLSource="properties.xml" --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" encoding="iso-8859-1"/><xsl:output method="xml" encoding="iso-8859-1"/><xsl:template name="location"><xsl:param name="Chiswick"/></xsl:template><xsl:template match="/">  <h2>Property Results:</h2>  <table width="20%" cellpadding="0" cellspacing="0" border="1">	<tr bgcolor="#9acd32">	  <th>Location</th>	  <th>Bedrooms</th>	  <th>Price</th>	</tr>	<xsl:for-each select="properties/property">	<xsl:sort select="location" order="ascending" />	<tr>	  <td>	  <xsl:variable name="Chiswick">	  <xsl:call-template name="location">	  <xsl:with-param name="Chiswick" select="location"/>	  </xsl:call-template>	  </xsl:variable>	  </td>   	  <xsl:choose>	  <xsl:when test="price > 10000">		 <td bgcolor="#ff00ff">		 <xsl:value-of select="bedrooms"/>		 </td>	  </xsl:when>	  <xsl:when test="price > 20000">		 <td bgcolor="#cccccc">		 <xsl:value-of select="bedrooms"/></td>	  </xsl:when>	  <xsl:otherwise>		 <td><xsl:value-of select="bedrooms"/></td>	  </xsl:otherwise>	  </xsl:choose>	  <td><xsl:value-of select="price"/></td>	  </tr>	</xsl:for-each>  </table></xsl:template></xsl:stylesheet>

Could you try putting an <xsl:if test ="(*whatever/node/path/needed/to = 'Chiswick')"> statement right after the <xsl:for-each select="properties/property"> ... this way you could test for whatever node holds Chiswick and then the rest of the code will not execute unless Chiswick is found. Remember to add the </xsl:if> before your </xsl:for-each> statement toward the bottom. Of course, I may be reading this wrong.
Link to comment
Share on other sites

Your template<xsl:template name="location"><xsl:param name="Chiswick"/></xsl:template>doesn't do anything. What it does is to create a parameter with no default value. After that, the template simply doesn't do anything. The value that was passed when calling the template with a with-param element is lost outside of this temlpate.So, that being said, when you call it, with or without any with-param elements, it still doesn't do anything.Whatever it is you're trying to achieve, this is not the way.

Link to comment
Share on other sites

Thanks cignaj & boen_robotI have tried putting this in - <xsl:if test ="(properties/property/location= 'Chiswick')"> I was not sure about the '*' you had just after the '(' - when i had it gave me an error. When it is out like above it runs but it displays the text outside the table I had in the xsl page.this is the error- Error Type:msxml3.dll (0x80004005)Expected token ')' found 'NAME'. (*-->properties<--/property/location = 'Chiswick')Do i need to have 'test' could that be 'location' - does it matter? It still filtered out all the locations - so do you think it may not be working or is there something else in the code that is preventing it from working - boen_robot said that the param bit is not actually doing the job properly! Should i take out the param tags or should i add something to make it work?Cheers

Link to comment
Share on other sites

Thanks cignaj & boen_robotI have tried putting this in - <xsl:if test ="(properties/property/location= 'Chiswick')"> I was not sure about the '*' you had just after the '(' - when i had it gave me an error. When it is out like above it runs but it displays the text outside the table I had in the xsl page.this is the error- Error Type:msxml3.dll (0x80004005)Expected token ')' found 'NAME'. (*-->properties<--/property/location = 'Chiswick')Do i need to have 'test' could that be 'location' - does it matter? It still filtered out all the locations - so do you think it may not be working or is there something else in the code that is preventing it from working - boen_robot said that the param bit is not actually doing the job properly! Should i take out the param tags or should i add something to make it work?Cheers
you were correct in not including the * i should have specified that ... i would try commenting out this part and see what happens ... <td> <xsl:variable name="Chiswick"> <xsl:call-template name="location"> <xsl:with-param name="Chiswick" select="location"/> </xsl:call-template> </xsl:variable> </td> with what you added i wouldn't think you would need this.
Link to comment
Share on other sites

Hello,I am trying to pull in the price and it displays the price but it also displays this symbol "Â".So it would be sopmething like this £325,000. I checked for any typos - but does not seem to be the case.The xml data that gets pulled in has the tag <xsl:value-of select="//price_text"/> and here is an example of an xml data: <price_text>£325,000</price_text>. The second problem is I can get all the locations from the xml data apllication which are all unique location names which i use this code:<xsl:for-each select="houses/property/address[contains(property_location,$XLlocation)]"> but the other items such as price, short description etc etc do not corrsopond top their location, instead they are all the same - e.g. the short description is displayed the same for each location - even though the short descriptions are different.Boen Robot suggested to use a template which i am trying to look up and get it to work in this code to get each item (e.g. short description) to corrospond to the location - would i change this bit: <xsl:template match="/"> to something else?Finally the parameter I have is being passed from the query but does not seem to filter with the parameter in the xslt page. For example the parameter is location and lets say the querystring is lo=Chiswick. Then it should display all the properties that have Chiswick as location.Currently it is displaying all locations.Here is my code for the paramter:

<xsl:for-each select="aspasia_data/houses/property/address[contains(property_location,$XLlocation)]">   <table width="70%" cellpadding="0" cellspacing="0" border="0" align="center">	<tr>	  <td colspan="2" bgcolor="#CC6633" style="color:#FFFFFF" bordercolor="#000000" align="left"> <strong><xsl:value-of select="property_location"/></strong></td></tr>

Any help on the above questions will be extremely gratefulCheers

Link to comment
Share on other sites

Boen Robot suggested to use a template which i am trying to look up and get it to work in this code to get each item (e.g. short description) to corrospond to the location - would i change this bit: <xsl:template match="/"> to something else?
Errr.... I suggested a named template. That is, another template with no match, but a name, which you can call at any point in the XSLT file.However, now that I actually ovserve a more descriptive path, I think I see the sole reason for most of your problems. Instead of creating a table for each adress, why not create a table for each house? Wouldn't that make more sence? And make tables only for the houses that are on a certain location. Something like that I mean:
<xsl:for-each select="aspasia_data/houses/property[contains(address/property_location,$XLlocation)]">  <table width="70%" cellpadding="0" cellspacing="0" border="0" align="center">	<tr>	  <td colspan="2" bgcolor="#CC6633" style="color:#FFFFFF" bordercolor="#000000" align="left"> <strong><xsl:value-of select="property_location"/></strong></td></tr>

For the price thingy. I really don't have any idea. Try to view the transformation in the browser (as processed by the browser, withOUT ASP). Actually, try it in more then one browser. Does the problem persist in all of them? If not, it's very likely this is a XSLT processor bug. And this can't be fixed. You'll have to upgrade to ASP.NET and use the .NET XSLT processor or another XSLT processor available for ASP(.NET).

Link to comment
Share on other sites

Thanks boen robot - sorry about not understanding you meant name template.I tried this <xsl:for-each select="aspasia_data/houses/property[contains(address/property_location,$XLlocation)]"> but it just stopped displaying the property location text and did not seem to resolve the problem with the other elements not displaying corrosponding to their property.Can you nest 'for-each' tags inside one and anoher? - seems wrong way of going about this but i am confussed how the other elements are within the 'for-each' tags are not working like the property location is working.The price thing i am thinking it may be a 'symbol' any idea which one it would be? I am thinking maybe it is being having problem with the node child '//' being just in front of the pound sign? If this is the case then maybe have to have a different way of finding the data instead of using nodes? What can you suggest? I have also tried your suggestion of trying it in other browsers - but i still get the symbol appearing in front of the pound sign.<quote>Instead of creating a table for each adress, why not create a table for each house?</quote> I think i got it to do that- i have got the 'for-each' tags for the table that will display each table with the contents. Here is the code:

<?xml version="1.0" encoding="iso-8859-1><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:param name="XLlocation"/><xsl:template match="/">  <h2>Property Results:</h2>	<xsl:for-each select="aspasia_data/houses/property/address[contains(property_location,$XLlocation)]">   <table width="70%" cellpadding="0" cellspacing="0" border="0" align="center">	<tr>	  <td colspan="2" bgcolor="#CC6633" style="color:#FFFFFF" bordercolor="#000000" align="left"> <strong><xsl:value-of select="property_location"/></strong></td>	<td bgcolor="#CC6633" style="color:#FFFFFF" bordercolor="#000000"><strong>	<xsl:value-of select="//price_text"/></strong></td>	</tr>	<tr bgcolor="#E1DDE1">	  <td colspan="2"><img src="{//picture1}"/></td>	  <td valign="top" width="82%"><xsl:value-of select="//short_description"/></td>	</tr>	<tr bgcolor="#E1DDE1">	  <td colspan="2"></td>	  <td height="30" valign="bottom" style="color:#000099">* <xsl:value-of select="//beds"/> Bedrooms * <xsl:value-of select="//baths"/> Bathrooms * <xsl:value-of select="//receptions"/> Receptions * <xsl:value-of select="//prag_code"/> * <xsl:value-of select="//prst_code"/> * <xsl:value-of select="//prty_code"/> * <xsl:value-of select="//prpa_code"/></td>	</tr>  </table>  <br /><br /></xsl:for-each></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Hi,I thought I would mention that the symbol in front of the price is fixed… hurrah!!I added this in the asp page<meta http-equiv="Content-Type" content="text/html; charset=utf-8">And changed <?xml version="1.0" encoding="iso-8859-1"?> to <?xml version="1.0" encoding="utf-8"?> in the xslt pageThese two problems i have yet to solve:1> That the data that corrosponds to the property location name for the first property works, but the second and the rest do not work in that the data corrosponds to the first property and not to the property location it should be corrosponding to.Example: The first one "Acton" is correct, but the Chiswick one is displaying the same data as Acton, when it should be displaying its own data. Why is that happening?Acton £325,000 A ground floor two bedroom garden flat that features a delightful 37' (11.3M) landscaped rear garden, office/summer house, private front door and off street parking. The accommodation comprises; reception room with doors to garden, kitchen, two bedrooms, bathroom, summer house/office, rear garden and off street parking. Newburgh Road is located with a selection of local shops near by as well as many amenities including swimming pool/fitness centres and good public transport. Detail Sheet * 2 Bedrooms * 1 Bathrooms * 1 Receptions * VICT * GARD * FLAT * PARK Google map | UpMyStreet | Slide Show | Floor Plan Chiswick £325,000 A ground floor two bedroom garden flat that features a delightful 37' (11.3M) landscaped rear garden, office/summer house, private front door and off street parking. The accommodation comprises; reception room with doors to garden, kitchen, two bedrooms, bathroom, summer house/office, rear garden and off street parking. Newburgh Road is located with a selection of local shops near by as well as many amenities including swimming pool/fitness centres and good public transport. Detail Sheet * 2 Bedrooms * 1 Bathrooms * 1 Receptions * VICT * GARD * FLAT * PARK Google map | UpMyStreet | Slide Show | Floor Plan 2> The text - * VICT * GARD * FLAT * PARK is in capitals and is short hand written in the XML data application like: <prag_code>VICT</prag_code> <prse_code>C</prse_code> <prst_code>TERR</prst_code> <prty_code>FLAT</prty_code> <prpa_code>STRT</prpa_code> But i want it to be displaying like this: Victoria, Flat, Street Parking, etc. How can i make it lowercase and Full words?Really grateful for any help or advice

Link to comment
Share on other sites

Try to use paths with no "//" at the beginning. Having that means XSLT will look for the first node in the whole document that matches the rest of the path. Without them, you're limiting the search to the first appropriate node, relative to the current context and ON the current context, rather then the whole document. If you want to find the first good node in the current context but also on all further nodes, use ".//" instead.For the short to long word, you'll have to hardcode conditions in the XSLT file. Sort of like that:

<xsl:choose><xsl:when test="prag_code = 'VICT'">Victoria</xsl:when><xsl:when test="prag_code = 'VICT'">C</xsl:when><!-- Print the prag_code if it is an unlisted one--><xsl:otherwise><xsl:value-of select="prag_code"/></xsl:otherwise></xsl:choose>

Link to comment
Share on other sites

Hi Boen Robert,Thanks for help.I tried taking out the node "//" - which resulted in not showing any of that data. I also tried ".//" which also resulted in not displaying that data. Why would it not display the data unless i have got "//" infront? There must be away to get around this - i tried put the full path for each item e.g.: houses/property/short_description - but again it would not display the data then.I tried putting in this bit of code for getting the text to lowercase and full length words:

For the short to long word, you'll have to hardcode conditions in the XSLT file. Sort of like that:
<xsl:choose><xsl:when test="prag_code = 'VICT'">Victoria</xsl:when><xsl:when test="prag_code = 'VICT'">C</xsl:when><!-- Print the prag_code if it is an unlisted one--><xsl:otherwise><xsl:value-of select="prag_code"/></xsl:otherwise></xsl:choose>

But i could not get it to work - this is how i have put it in- is it correct? -
<td height="30" valign="bottom" style="color:#000099">* <xsl:value-of select="//beds"/> Bedroom(s) * <xsl:value-of select="//baths"/> Bathroom(s) * <xsl:value-of select="//receptions"/> Reception(s) * <xsl:choose><xsl:when test="prag_code = 'VICT'">Victoria</xsl:when><xsl:when test="prag_code = 'VICT'">C</xsl:when><!-- Print the prag_code if it is an unlisted one--><xsl:otherwise><xsl:value-of select="prag_code"/></xsl:otherwise></xsl:choose></td>

Thank you for your help on this

Link to comment
Share on other sites

Hi Boen Robert,I tried putting in this bit of code for getting the text to lowercase and full length words:But i could not get it to work - this is how i have put it in- is it correct? -
<td height="30" valign="bottom" style="color:#000099">* <xsl:value-of select="//beds"/> Bedroom(s) * <xsl:value-of select="//baths"/> Bathroom(s) * <xsl:value-of select="//receptions"/> Reception(s) * <xsl:choose><xsl:when test="prag_code = 'VICT'">Victoria</xsl:when><xsl:when test="prag_code = 'VICT'">C</xsl:when><!-- Print the prag_code if it is an unlisted one--><xsl:otherwise><xsl:value-of select="prag_code"/></xsl:otherwise></xsl:choose></td>

Sorry - This does work - i just needed to put "//" infront of "prag_code".So the last problem to solve...
I tried taking out the node "//" - which resulted in not showing any of that data. I also tried ".//" which also resulted in not displaying that data. Why would it not display the data unless i have got "//" infront? There must be away to get around this - i tried put the full path for each item e.g.: houses/property/short_description - but again it would not display the data then.
Thank you for your help on this
Link to comment
Share on other sites

Sorry - This does work - i just needed to put "//" infront of "prag_code".So the last problem to solve...Thank you for your help on this
There's no way to help you without a sample XML code. I need one to at least contain every node you're trying to output. Other nodes (which aren't influenced by this XSLT) could remain hidden if you're trying to hide them.
Link to comment
Share on other sites

Hi Boen Robot,I was not trying to hide them from you, just found that "//" was the only way to get it to work - // finds the child nodes - but you were right that it was the wrong way of going about it because it was not finding the property location that it corrosponds too.I have got the full path in now and i took out the <xsl:for-each select="aspasia_data/houses/property/address[contains(property_location,$XLlocation)]"> so i could get the full path that you said it should be for the tags to work.I know that i need some how to pass the parameter for example locaton-=chiswick or price=35000 etc. So i was thinking that i may use the asp page to pass the parameter. What do you think?The page works well now - so cheers or your help. The only minor bits that i am getting stuck on are:>To be able to put a space between one tag and another - so when it dispalys it has a space between the words. I tried using   but that gives me an error on xml validation. So how can i put a space between the words?>Second small error i have is a link that goes to google and up-your-street pages that use the postcode tag to put the query so the google shows the map with the postcode.This is the code i got - it works for the first property but that is because i put the actual postcode in the query.

<A HREF="java script: f_NewWin('http://maps.google.co.uk/maps?q=W4+2BU',850,600)" OnMouseOver="window.status='View local map';return true;" OnMouseOut="window.status='';return true;">Google map</A>

So i thought i could do this by putting the xml tag <postcode> inside the url (but does not seem to work!):

<A HREF="java script: f_NewWin('http://maps.google.co.uk/maps?q='postcode',850,600)" OnMouseOver="window.status='View local map';return true;" OnMouseOut="window.status='';return true;">Google map</A>

This is the up your street url:

<A HREF="java script: f_NewWin('http://www.upmystreet.co.uk/overview/?l1=W4+2BU',850,600)" OnMouseOver="window.status='Up My Street';return true;" OnMouseOut="window.status='';return true;">UpMyStreet</A>

The javascript i have put into my asp code for these external links:

<script LANGUAGE="JavaScript"><!--if (navigator.appName.indexOf("Netscape") >= 0) {	document.write("<STYLE TYPE=\"text/css\">");	document.write("P,LI,UL,PRE,INPUT,TEXTAREA,OPTION,SELECT,TD,TABLE {font-size: 8pt;}");	document.write("</STYLE>");}function focusBack(){null;}function unload_f(){null;}var OpenWin;function f_NewWin(page,pWidth,pHeight,pToolbar,pWinName,pFeatures) {	var postop = 5,posleft = 5,vFeatures = pFeatures;	if (pToolbar=="N") vToolbar = "no"; else  vToolbar = "yes";	if (pFeatures=="" || pFeatures==null) vFeatures = "buttons=no,scrollbars=yes,location=no,menubar=no,resizable=yes,status=no,directories=no";	if (pWidth=="" || pWidth==null) v_width = screen.availwidth - 20;	else {v_width = pWidth}	if (pWinName=="" || pWinName==null) vWinName = "f_NewWin";	else {vWinName = pWinName}	posleft = (screen.availwidth - v_width) / 2;	if (pHeight=="" || pHeight==null) v_height = screen.availheight - 100;	else {v_height = pHeight}	postop = (screen.availheight - v_height - 50) / 2;	OpenWin = this.open(page, vWinName, "top="+postop+",left="+posleft+",width=" + v_width + ",height=" + v_height + ","+vFeatures+",toolbar=" + vToolbar);	OpenWin.focus();}function f_HelpWin(page,pWidth,pHeight) {	v_width = 550;	v_height = 400;	var postop = 5,posleft = 5;	if (pWidth != null) v_width = pWidth;	if (pHeight != null) v_height = pHeight;	posleft = (screen.availwidth - v_width) / 2;	postop = (screen.availheight - v_height) / 2;	OpenWin = this.open(page, "HelpWin","top="+postop+",left="+posleft+",width=" + v_width + ",height=" + v_height + ",buttons=no,scrollbars=yes,location=no,menubar=no,resizable=yes,status=no,directories=no,toolbar=no");	OpenWin.focus();}function loader(){null;}//--></SCRIPT>

How can i get the postcode xml tag to be displayed in the url - so it is unique to each property?Cheers again for the help.

Link to comment
Share on other sites

>To be able to put a space between one tag and another
You mean in the output HTML, right? Well, for that, you could use either the CSS property
white-space:pre;

on the nodes containing such extra spaces or (the solution I suppose you'll prefer), use a numeric entity instead of the named one. According to W3Schools' entity reference & nbsp; is & #160;

How can i get the postcode xml tag to be displayed in the url
The same way you can embed any other XML value in an attribute value. With an atribute value template (AVT).
<A HREF="java script: f_NewWin('http://maps.google.co.uk/maps?q={postcode},850,600)" OnMouseOver="window.status='View local map';return true;" OnMouseOut="window.status='';return true;">Google map</A>

Notice the {postcode} bit. That fetches the value of the postcode element and puts it in that spot.

Link to comment
Share on other sites

Hi,Thanks for the help on the google and Upyourstreet external links. ({xyz} kind of gets what ever the value of that tag?)I tried putting #160; like this:

* #160;<xsl:value-of select="property_summary/beds"/> Bedroom(s) #160;* #160;<xsl:value-of select="property_summary/baths"/> Bathroom(s)

but just writes out * #160; 2 Bedroom(s) #160; * #160; 1 BathroomMaybe i have not put the #160; correctly into the code?Cheers,

Link to comment
Share on other sites

Hi,Thanks for the help on the google and Upyourstreet external links. ({xyz} kind of gets what ever the value of that tag?)I tried putting #160; like this:
* #160;<xsl:value-of select="property_summary/beds"/> Bedroom(s) #160;* #160;<xsl:value-of select="property_summary/baths"/> Bathroom(s)

but just writes out * #160; 2 Bedroom(s) #160; * #160; 1 BathroomMaybe i have not put the #160; correctly into the code?Cheers,

Someone has forgot their ampersand (&) this morning :) . The only reason I added space when I mentioned it was because this board interprets the entity. If there was no space, you were going to see only a single non breaking space (sounds silly... I know).
Link to comment
Share on other sites

Someone has forgot their ampersand (&) this morning :) . The only reason I added space when I mentioned it was because this board interprets the entity. If there was no space, you were going to see only a single non breaking space (sounds silly... I know).
Spot on! :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...