Jump to content
  • 0

XSL file voor Google API


Meeuwis

Question

Goedemiddag,

Sinds kort gebruiken wij een API van Google om adres gegevens op te zoeken. Via de volgende XML-output van Google zou ik graag de afzonderlijke adrescomponenten (<address_component>) in aparte velden in het Klantenbestand zetten. Hoe kan ik een specifiek veld in een XML veld selecteren? Er zijn namelijk meerdere regels de <address_component> bevatten, alleen het <type> verschilt.

Als ik records wil importeren heb ik ook een XSL-file nodig. Hoe kan ik deze genereren op basis van de volgende XML sheet?

Wij gebruiken Filemaker 14

Groeten, Meeuwis

 
<GeocodeResponse>
<status>OK</status>
<result>
<type>street_address</type>
<formatted_address>Voorzand 40, 2984 BH Ridderkerk, Nederland</formatted_address>
<address_component>
<long_name>40</long_name>
<short_name>40</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Voorzand</long_name>
<short_name>Voorzand</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Ridderkerk</long_name>
<short_name>Ridderkerk</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Ridderkerk</long_name>
<short_name>Ridderkerk</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Zuid-Holland</long_name>
<short_name>ZH</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Nederland</long_name>
<short_name>NL</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>2984 BH</long_name>
<short_name>2984 BH</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>51.8706045</lat>
<lng>4.6081025</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>51.8692555</lat>
<lng>4.6067535</lng>
</southwest>
<northeast>
<lat>51.8719535</lat>
<lng>4.6094515</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJIQx9HbktxEcRy3U2S4TqIqA</place_id>
</result>
</GeocodeResponse>
Link to comment

3 answers to this question

Recommended Posts

  • 1

Ik heb de onderstaande xsl een paar jaar geleden gemaakt .... die kan je voor jezelf uitbreiden ... dit is dan slechts een begin:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:default="GeoCodeResponse.xml">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="/">
        <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
            <ERRORCODE>0</ERRORCODE>
            <PRODUCT BUILD="" NAME="" VERSION=""/>
            <DATABASE DATEFORMAT="DD-MM-YYYY" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>
            <METADATA>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Status" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Adres" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Long" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Lat" TYPE="TEXT"/>
            </METADATA>
            <RESULTSET>
                <xsl:attribute name="FOUND"/>
                <xsl:for-each select="GeocodeResponse">
                    <ROW MODID="0">
                        <xsl:attribute name="RECORDID"><xsl:value-of select="position()"/></xsl:attribute>
                        <COL>
                            <DATA>
                                <xsl:value-of select="status"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/formatted_address"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/geometry/location/lng"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/geometry/location/lat"/>
                            </DATA>
                        </COL>
                    </ROW>
                </xsl:for-each>
            </RESULTSET>
        </FMPXMLRESULT>
    </xsl:template>
</xsl:stylesheet>

 

Edited by menno
Link to comment
  • 1

Je kan ook specifieke waarden selecteren zoals de postcode. Ik heb daarvoor de voorgaande xsl ietsje aangepast:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:default="GeoCodeResponse.xml">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="/">
        <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
            <ERRORCODE>0</ERRORCODE>
            <PRODUCT BUILD="" NAME="" VERSION=""/>
            <DATABASE DATEFORMAT="DD-MM-YYYY" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>
            <METADATA>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Status" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Adres" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Long" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Lat" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Postcode" TYPE="TEXT"/>
            </METADATA>
            <RESULTSET>
                <xsl:attribute name="FOUND"/>
                <xsl:for-each select="GeocodeResponse">
                    <ROW MODID="0">
                        <xsl:attribute name="RECORDID"><xsl:value-of select="position()"/></xsl:attribute>
                        <COL>
                            <DATA>
                                <xsl:value-of select="status"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/formatted_address"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/geometry/location/lng"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/geometry/location/lat"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="result/address_component[type='postal_code']/long_name"/>
                            </DATA>
                        </COL>
                    </ROW>
                </xsl:for-each>
            </RESULTSET>
        </FMPXMLRESULT>
    </xsl:template>
</xsl:stylesheet>

Hier kan je zelf de rest wat je nodig hebt wel aan toevoegen :-) 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...