XML newbie question - spot the difference

B

blingk

I'm an XML newbie trying to add a property search and a featured
property to an estate agent's website using various XML bits sent to
me by the people who host their properties (a company called Dezrez).

Click here to see what the XML returned looks like for the property
search results...
http://data.dezrez.com/search.asp?wci=results&xslt=-1&eaid=639&perpage=32000&showstc=on

....and here to see it for the featured properties results...
http://www.dezrez.com/webservices/featured/featuredProperty.aspx?eaid=639&number=3&;showxml=1

Is this latter XML formed properly? The first one is recognized as XML
by the browser but the second seems to be interpreted as a web page
(which might be why I am getting no results when running this through
XSL or XSLT files??)
 
M

Martin Honnen

blingk said:
I'm an XML newbie trying to add a property search and a featured
property to an estate agent's website using various XML bits sent to
me by the people who host their properties (a company called Dezrez).

Click here to see what the XML returned looks like for the property
search results...
http://data.dezrez.com/search.asp?wci=results&xslt=-1&eaid=639&perpage=32000&showstc=on

...and here to see it for the featured properties results...
http://www.dezrez.com/webservices/featured/featuredProperty.aspx?eaid=639&number=3&;showxml=1

Is this latter XML formed properly? The first one is recognized as XML
by the browser but the second seems to be interpreted as a web page
(which might be why I am getting no results when running this through
XSL or XSLT files??)

It is not a problem with the XML contents but rather a question of the
HTTP header the contents is served with. For the first URL it is
text/xml, for the second it is text/html. If you want to serve XML with
ASP then make sure your code sets e.g.
Response.ContentType = "application/xml"
or
Response.ContentType = "text/xml"
before your page sends any contents to the client.
 
B

blingk

It is not a problem with the XML contents but rather a question of the
HTTP header the contents is served with. For the first URL it is
text/xml, for the second it is text/html. If you want to serve XML with
ASP then make sure your code sets e.g.
Response.ContentType = "application/xml"
or
Response.ContentType = "text/xml"
before your page sends any contents to the client.

Ok thanks for that, gets me a bit closer.

I'm still struggling to get this working though. I've got 2 tests on
the go, both using the results from...
http://www.dezrez.com/webservices/featured/featuredProperty.aspx?eaid=639&number=3&showxml=1
(slightly corrupted in my original message).

**** Test 1: Files are features2.asp & test.xsl ****

---test.xsl---

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>TEST</h2>
<table border="1">
<xsl:for-each select="properties/property">
<tr>
<td><xsl:value-of select="price" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>



--featured2.asp---

<%
Response.ContentType = "text/xml"

dim sLink
dim xslt
dim oHttpRequest
dim outputHTML

sLink = "http://www.dezrez.com/webservices/featured/
featuredProperty.aspx?eaid=639&number=3&showxml=1"

'response.write(sLink)
'xml request objects
'Load XML

Set XML = Server.CreateObject("Microsoft.XMLDOM")
set xmlhttp=createObject("Microsoft.XMLHTTP")
xmlhttp.onreadystatechange=getRef("stateChange")
xmlhttp.Open "POST", sLink, false
xmlhttp.Send()

'dim blah
'blah = xmlhttp.responseText

'XML received
function stateChange()


dim num
if xmlhttp.readyState=4 then
if xmlhttp.status=200 then
xml.load (xmlhttp.responseXML)

'load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("test.xsl"))

'Transform file
outputHTML = xml.transformNode(xsl)
else
Response.Write("XML data not OK")
Response.Write(xmlhttp.responseXML)
end if
end if


end function
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<%
Response.write(outputHTML)
'Response.write(blah)
%>
</body>
</html>


Result = just the heading TEST


What am I doing wrong here?
 
B

blingk

My other test, using an XSLT file currently looks like this...

Files - featured.asp & searchresults4.xslt

---- searchresults4.xslt ----

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<xsl:value-of select select="count(properties/property)"/>
</xsl:template>
</xsl:stylesheet>


The idea is that as a basic test we just count the number of property
nodes.


---- featured.asp ----

Exactly as posted previously but pointed at the xslt file above...

xsl.load(Server.MapPath("searchresults4.xslt"))


---- Result: "The stylesheet does not contain a document element. The
stylesheet may be empty, or it may not be a well-formed XML document."
 
M

Martin Honnen

blingk said:
My other test, using an XSLT file currently looks like this...

Files - featured.asp & searchresults4.xslt

---- searchresults4.xslt ----

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<xsl:value-of select select="count(properties/property)"/>
^^^^^^^^
That is not well-formed XML.
 
B

blingk

^^^^^^^^
That is not well-formed XML.


Yes, thanks, well spotted. Fixing this line stops the errors, but
isn't returning the right result. If you look at the XML file, there
are 3 featured properties. The result I now get is '0'.

Still something I'm doing wrong here obviously. As a test I tried
changing the XSLT to...

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="properties"/>
</xsl:template>
<xsl:template match="properties">
<xsl:for-each select="property">
<div>
<xsl:value-of select="description1"/>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

....in case the count method was being used wrongly somehow. The result
of the above is a blank page (as if there are no results).
 
M

Martin Honnen

blingk said:
Still something I'm doing wrong here obviously. As a test I tried
changing the XSLT to...

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="properties"/>
</xsl:template>
<xsl:template match="properties">
<xsl:for-each select="property">
<div>
<xsl:value-of select="description1"/>

The XML sample is long and poorly formatted for human reading but it
looks as if the child element name is 'description' and not
'description1' so you need
<xsl:value-of select="description"/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top