Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:21:11+00:00 2026-06-04T10:21:11+00:00

An OpenStreetMap xml document is composed (among other things) of a set of node

  • 0

An OpenStreetMap xml document is composed (among other things) of a set of “node” elements and a set of “way” elements.

The “node” elements can (optionally) nest “tag” elements.

The “way” elements are composed by an ordered list of “node” elements, referenced by the nested elements “nd”, with their attribute “ref” pointing to the attribute “id” at the “node” elements.

Here an example:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
  <node id="1726631203" lat="50.8500083" lon="4.3553223" visible="true" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
  ...
  <way id="160611697" user="toSc" uid="246723" visible="true" version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
    <nd ref="1726631203"/>
    <nd ref="1726631223"/>
    <nd ref="1726631213"/>
    <nd ref="1726631205"/>
    <nd ref="1726631185"/>
    <nd ref="1726631203"/>
  </way>
  ...
</osm>

My question is how, using XSLT, could I do the following transformation ?

  • Filtering all the node elements that are not referenced by any way element.
  • Filtering the way elements that reference node elements not included in the source xml document.
  • Changing the attribute “visible” to “false”, to any “node” element not having “tag” children elements.

Any other elements should remain in the generated xml.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:21:12+00:00Added an answer on June 4, 2026 at 10:21 am

    My question is how, using XSLT, could I do the following
    transformation ?

    • Filtering all the node elements that are not referenced by any way element.

    • Filtering the way elements that reference node elements not included in the source xml document.

    • Changing the attribute “visible” to “false”, to any “node” element not having “tag” children elements.

    This transformation fullfills all three requirements:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kND-By-Ref" match="way/nd" use="@ref"/>
     <xsl:key name="kNodeById" match="node" use="@id"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="node[not(key('kND-By-Ref', @id))]"/>
     <xsl:template match="way[nd[not(key('kNodeById', @ref))]]"/>
    
     <xsl:template match="node[not(tag)]/@visible">
      <xsl:attribute name="visible">false</xsl:attribute>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document (suitably created to contain a case for each requirement):

    <osm version="0.6" generator="CGImap 0.0.2">
        <node id="1726631203" lat="50.8500083" lon="4.3553223" visible="true"
          version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z">
          <tag/>
     </node>
        <node id="1726631223" lat="50.8500083" lon="4.3553223" visible="true"
          version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
        <node id="ZZZZZZZ" lat="50.8500083" lon="4.3553223" visible="true"
          version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
        <way id="160611697" user="toSc" uid="246723" visible="true"
          version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
            <nd ref="1726631203"/>
            <nd ref="1726631223"/>
        </way>
        <way id="160611698" user="toSc" uid="246723" visible="true"
          version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
            <nd ref="1726631203"/>
            <nd ref="1726631223"/>
            <nd ref="1726631213"/>
            <nd ref="1726631205"/>
            <nd ref="1726631185"/>
            <nd ref="1726631203"/>
        </way>
    </osm>
    

    the wanted, correct result (all filterings are performed and the visible attribute of one of the node elements is turned to false) is produced:

    <osm version="0.6" generator="CGImap 0.0.2">
       <node id="1726631203" lat="50.8500083" lon="4.3553223"
        visible="true" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z">
          <tag/>
       </node>
       <node id="1726631223" lat="50.8500083" lon="4.3553223"
        visible="false" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
       <way id="160611697" user="toSc" uid="246723" visible="true"
        version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
          <nd ref="1726631203"/>
          <nd ref="1726631223"/>
       </way>
    </osm>
    

    Explanation:

    1. The identity rule is overriden by three templates, each implementing one of the three requirements.

    2. The two overriding templates that have empty bodies implement the two filtering requirements.

    3. We are using keys to conveniently and efficiently find node s by their id attribute and nd s by their ref attribute.

    4. The attribute value replacement requirement is implemented in the third overriding template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did you know a way to render the .osm format given by OpenStreetMap in
Is there a way to embed/mashup the OpenStreetMap in your page (like the way
I want to get some node (for example, schools, kindergartens) from Planet.osm (http://wiki.openstreetmap.org/wiki/Planet.osm), the
I have written a converter that takes openstreetmap xml files and converts them to
I'm using http://www.openstreetmap.org/ export utility to generate a .osm (xml map file) of an
I'm using OpenLayers to display an openstreetmap. Is there a way to edit certain
Rendering a 3D-map from an Openstreetmap data can be pretty cumbersome . But what
I'm working with OpenStreet Maps in Java with JMap Viwer http://wiki.openstreetmap.org/wiki/JMapViewer I can load
I'm using OpenLayers to display OpenStreetMap maps. (Though, I'd assume this should be general
I am looking into MapQuest API for OpenStreetMap and it seems to be a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.