DaveF
DaveF

Reputation: 173

XPath: How do I return only one child element, but retain the tree structure?

I'm using this XPath to filter out data.

.selectNodes("(//delete/node|//delete/way)[tag[@k='railway'][@v='station' or @v='platform']]")

It returns this, as expected.

<delete>
    <way id="48016377">
        <nd ref="610578972"/>
        <sys bic="gb"/>
        <tag k="railway" v="platform"/>
    </way>
    <node id="797115753">
        <nd ref="3035237104"/>
        <nd ref="2473620966"/>
        <nm top="left"/>
        <tag k="electrified" v="contact_line"/>
        <tag k="railway" v="station"/>
    </node>
</delete>

How to I amend it so it returns only the tag elements, but retains the tree structure?

<delete>
    <way id="48016377">
        <tag k="railway" v="platform"/>
    </way>
    <node id="797115753">
        <tag k="electrified" v="contact_line"/>
        <tag k="railway" v="station"/>
    </node>
</delete>

Upvotes: 0

Views: 29

Answers (0)

Related Questions