[OSM-newbies] XSLT question
Andrew Errington
a.errington at lancaster.ac.uk
Wed Sep 16 04:30:57 BST 2009
On Tue, September 15, 2009 16:00, Andrew Errington wrote:
> On Tue, September 15, 2009 14:55, Renaud MICHEL wrote:
> <snip>
>> You can make it a lot simpler with an xpath like I gave before:
>>
>> <xsl:template match="node[tag[@k='amenity' and @v=$amenity]]">
I'm afraid I couldn't get this to work. xsltproc complained. :(
I don't have the error message, but I could run it again and tell you if
you're interested.
I have had some success with extracting lat/lon pairs for
amenities-which-are-areas. Here's my code, and thank you for the tip
about xsl:key.
<xsl:key name="nodes" match="node" use="@id"/>
<xsl:template match="way">
<xsl:for-each select="tag">
<xsl:if test='@k="amenity" and @v=$amenity'>
<xsl:value-of select='../tag[@k="name"]/@v'/><br/>
<xsl:value-of select='../@id'/><br/>
<xsl:for-each select="../nd[position()>1]">
<xsl:value-of select="key('nodes', at ref)/@lat"/><br/>
<xsl:value-of select="key('nodes', at ref)/@lon"/><br/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
So far it will dump a list of amenities with their name and way id,
followed by a list of lat/lons for each point around the perimeter. I
have avoided the first point as it is duplicated as the last point (to
make a closed way). I want to calculate average(lat) and average(lon) as
an inexpensive centroid so that I can derive a single point for an amenity
that is an area.
Unfortunately my XSLT-fu is very weak. I haven't grasped how to make a
result set of lats and a result set of lons. If I could do that then I
could sum() them and count() them and calculate the average.
Hints and tips are appreciated. If you want to do my homework for me then
please do so, but please give me comments about how it's done, so I can
learn. Once it's working I will add it to the OSM wiki as I think it will
be useful.
Best wishes,
Andrew
More information about the newbies
mailing list