CCBtx Posted February 18, 2013 Posted February 18, 2013 I have attached the XML Response. I am trying to get all data elements in one row and in one table. The index for this particular row is ID 6018 which is Colorado, Denver, Montbello. I can get the region and links just fine. What I am having trouble with is the repeating elements for charts an pages Out of Charts, I have table field names for (i) Median Condo Value, (ii) Median Home Value, (iii) Dollars Per Square Feet, (iv) Dollars Per Square Feet and so on. However, you will notice those are returned as the <name> field in each element. For charts, I need the URL of those names. Out of Pages, I need the Neighborhood, City, and Nation values for the attributes named "Median Single Family Home Value" and "Median Condo Value" as I have those fields as well. Thanks very much for looking. One example for each should kick me down the road. CCB GetDemographics.xml
Opotoc Posted February 18, 2013 Posted February 18, 2013 Hi CCB, you need to loop through with <xsl:for-each> . Best, Alexander <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:Demographics="http://www.zillow.com/static/xsd/Demographics.xsd" exclude-result-prefixes="xd Demographics" version="1.0"> <xsl:template match="/*"> <table> <xsl:for-each select="response/charts/chart"> <tr> <td> <xsl:value-of select="name"/> </td> <td> <xsl:value-of select="url"/> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
CCBtx Posted February 18, 2013 Author Posted February 18, 2013 Alexander: I could not get yours to work with the <tr> and <td>. Instead I used the one below and it loops just like you suggested. Is there a way to import the data into one row rather than looping? <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD="" NAME="FileMaker" VERSION="ProAdvanced 12.0v2"/> <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/> <METADATA> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="name" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="url" TYPE="TEXT" /> </METADATA> <RESULTSET FOUND=""> <xsl:for-each select="//charts/chart"> <ROW RECORDID="" MODID="" > <COL><DATA><xsl:value-of select="name"/></DATA></COL> <COL><DATA><xsl:value-of select="url"/></DATA></COL> </ROW> </xsl:for-each> </RESULTSET> </FMPXMLRESULT> </xsl:template> </xsl:stylesheet>
CCBtx Posted February 18, 2013 Author Posted February 18, 2013 Alexander: Thank you again for your reply. After looking at this, I dont really think it is a loop... because I want all of the data elements in this particular XML in just one data row. So... I went back and read some of Comment's comments (including his direction to w3webschools), and constucted the following which works great. If anyone knows a more straight forward approach... feel free to post. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD="" NAME="FileMaker" VERSION="ProAdvanced 12.0v2"/> <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/> <METADATA> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Chart.Value.MedianCondo" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Chart.Value.MedianHome" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Chart.Value.DollasSqFt" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Chart.OwnervsRenter" TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Value.MedianSingleFamily" TYPE="TEXT" /> </METADATA> <RESULTSET FOUND=""> <ROW RECORDID="" MODID="" > <COL><DATA><xsl:value-of select="//charts/chart[name='Median Condo Value']/url"/></DATA></COL> <COL><DATA><xsl:value-of select="//charts/chart[name='Median Home Value']/url"/></DATA></COL> <COL><DATA><xsl:value-of select="//charts/chart[name='Dollars Per Square Feet']/url"/></DATA></COL> <COL><DATA><xsl:value-of select="//charts/chart[name='Owners vs. Renters']/url"/></DATA></COL> <COL><DATA><xsl:value-of select="//pages/page[name='Affordability']/tables/table/data/attribute[name='Median Single Family Home Value']/values/city/value"/></DATA></COL> </ROW> </RESULTSET> </FMPXMLRESULT> </xsl:template> </xsl:stylesheet>
Opotoc Posted February 19, 2013 Posted February 19, 2013 Hi CCB, mine was just an example that's why I chose an html table as output to demonstrate. If you only need to import one record the above works fine, glad you found a solution. Cheers, Alexander
Recommended Posts
This topic is 4362 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now