[OSM-newbies] XSLT question

Andrew Errington a.errington at lancaster.ac.uk
Tue Sep 15 05:40:43 BST 2009


On Tue, September 15, 2009 03:30, Renaud MICHEL wrote:
> Hello
> Le lundi 14 septembre 2009 à 14:37, Andrew Errington a écrit :
>
>> So far I have a very simple XSLT that will find all nodes (or ways,
>> because a restaurant could be a node or an area) that have a tag with an
>>  attribute k="amenity" and an attribute v="restaurant".  I can query
>> the parent node and get its id, but I really want to query the sibling
>> nodes, find the one that has attribute k="name" and print the value of
>> attribute v (the name itself).
>
> You can select those elements with an xpath like
>
>
> node[tag[@k='amenity' and @v='restaurant']]/tag[@k='name']
>
> for more informations, see http://www.w3.org/TR/xpath
> http://www.w3.org/TR/xslt

Hi,

Thanks for your help.  I have made this, which is part of the solution I
want:

<xsl:template match="node">
  <xsl:for-each select="tag">
    <xsl:if test='@k="amenity" and @v=$amenity'>
      <xsl:value-of select='../@id'/><br/>
      <xsl:value-of select='../@lat'/><br/>
      <xsl:value-of select='../@lon'/><br/>
      <xsl:value-of select='../tag[@k="name"]/@v'/>
      <br/>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

I am using xsltproc under Linux, and I can set the $amenity parameter on
the command line.  This fragment will return all amenities which are
nodes, but not areas.  I have some more work to do there.

For an area I will match "way" but then I have to get all nodes that make
the way and calculate a simple centroid.

The final output will be a list of named lat/lon pairs for any amenity. 
If there is an easier way, please tell me, but for now I am enjoying
dabbling with XSLT.

Best wishes,

Andrew





More information about the newbies mailing list