W
westguard
Hi
I am trying to get XML data from Facebook sorted, i.e. A-Z! The FQL
from Facebook does not allow you to sort the output, therefore I am
trying to use XSL to sort the XML data before doing anything with it.
I am retrieving the XML using an ASP (Not .Net) script, which works
fine. I am then trying to transform the XML using XSL to sort the data
A-Z. I basically want to list a users friend list alphabetically A-Z.
What seems to be throwing it is this line in the XML:
<fql_query_response xmlns="http://api.facebook.com/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance" list="true">
If I change this (and the closing tag) to <data> or something else
without the attributes, my code works fine, but I need it to work with
the fql_query_response tag - I don't want to mess with the XML before
applying the XSL. I suspect the namespace references is what is
confusing me.
Here is my code so far (this is by no means final, it just represents
how far my 'hacking' has come so far!):
**** XML (Sample - This is fixed from Facebook and cannot be
changed)****
<?xml version="1.0" encoding="ISO-8859-1"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance" list="true">
<user>
<uid>12345</uid>
<first_name>Joe</first_name>
<last_name>Bloggs</last_name>
</user>
<user>
.... etc
</user>
</fql_query_response>
**** XSL (Something like this) ****
<?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="/">
<xsl:for-each select="user">
<xsl:sort select="first_name"/>
<user>
<uid><xsl:value-of select="uid"/></uid>
<first_name><xsl:value-of select="first_name"/></first_name>
<last_name><xsl:value-of select="last_name"/></last_name>
</user>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
**** ASP Script (Extract) ****
Dim oXML
Set oXML = Server.CreateObject("Microsoft.XMLDOM")
oXML.async = false
oXML.load(Server.MapPath("/facebook/test.xml"))
Dim oXSL
Set oXSL = Server.CreateObject("Microsoft.XMLDOM")
oXSL.async = false
oXSL.load(Server.MapPath("/facebook/test.xsl"))
response.Write(oXML.transformNode(oXSL))
Note that I am loading the XML and XSL files in manually at the moment
and both report no problems when loading. I've even tried really
simple XSL stuff on the <user> nodes but it just won't pick that up.
How do I referencce the <user> nodes the XSL in order that it is
picked up and processed by tranformNode? I've tried so many different
XSL variations and have not had any luck.
Any feedback or suggestions would be greatly appreciated and I
apologize in advance if I am doing something completely silly!
Mark
I am trying to get XML data from Facebook sorted, i.e. A-Z! The FQL
from Facebook does not allow you to sort the output, therefore I am
trying to use XSL to sort the XML data before doing anything with it.
I am retrieving the XML using an ASP (Not .Net) script, which works
fine. I am then trying to transform the XML using XSL to sort the data
A-Z. I basically want to list a users friend list alphabetically A-Z.
What seems to be throwing it is this line in the XML:
<fql_query_response xmlns="http://api.facebook.com/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance" list="true">
If I change this (and the closing tag) to <data> or something else
without the attributes, my code works fine, but I need it to work with
the fql_query_response tag - I don't want to mess with the XML before
applying the XSL. I suspect the namespace references is what is
confusing me.
Here is my code so far (this is by no means final, it just represents
how far my 'hacking' has come so far!):
**** XML (Sample - This is fixed from Facebook and cannot be
changed)****
<?xml version="1.0" encoding="ISO-8859-1"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance" list="true">
<user>
<uid>12345</uid>
<first_name>Joe</first_name>
<last_name>Bloggs</last_name>
</user>
<user>
.... etc
</user>
</fql_query_response>
**** XSL (Something like this) ****
<?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="/">
<xsl:for-each select="user">
<xsl:sort select="first_name"/>
<user>
<uid><xsl:value-of select="uid"/></uid>
<first_name><xsl:value-of select="first_name"/></first_name>
<last_name><xsl:value-of select="last_name"/></last_name>
</user>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
**** ASP Script (Extract) ****
Dim oXML
Set oXML = Server.CreateObject("Microsoft.XMLDOM")
oXML.async = false
oXML.load(Server.MapPath("/facebook/test.xml"))
Dim oXSL
Set oXSL = Server.CreateObject("Microsoft.XMLDOM")
oXSL.async = false
oXSL.load(Server.MapPath("/facebook/test.xsl"))
response.Write(oXML.transformNode(oXSL))
Note that I am loading the XML and XSL files in manually at the moment
and both report no problems when loading. I've even tried really
simple XSL stuff on the <user> nodes but it just won't pick that up.
How do I referencce the <user> nodes the XSL in order that it is
picked up and processed by tranformNode? I've tried so many different
XSL variations and have not had any luck.
Any feedback or suggestions would be greatly appreciated and I
apologize in advance if I am doing something completely silly!
Mark