Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Another XML XSLT Question

Featured Replies

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

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>
  • Author

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>

  • Author

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>

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

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.