ivanz
ivanz

Reputation: 815

Xpath up one level

i would like to use this XPath expression

/moviedb/movie/title[@lang="english"] | /moviedb/movie/title[@lang="english"]/..runtime

I would like to filter out movies with attribute "english" in title and their runtime, but i dont know how to go back to /moviedb/movie once I am in /moviedb/movie/title full XML file:

<moviedb>
<movie>
    <imdbid>tt0838283</imdbid>
    <genres>Comedy</genres>
    <languages>English,Spanish</languages>
    <country>USA</country>
    <rating>6.8</rating>
    <runtime>106</runtime>
    <title lang="spanish">Step Brothers</title>
    <year>2008</year>
  </movie>
  <movie>
    <imdbid>tt2886734</imdbid>
    <genres>Drama</genres>
    <languages>English</languages>
    <country>USA</country>
    <rating>7.5</rating>
    <runtime>125</runtime>
    <title lang="english">A Life, Taken</title>
    <year>2014</year>
  </movie>
</moviedb>

thanks

Upvotes: 3

Views: 6362

Answers (1)

alecxe
alecxe

Reputation: 473983

You can do it this way:

/moviedb/movie[./title/@lang="english"]/runtime

Demo (using xmllint):

$ xmllint input.xml --xpath '/moviedb/movie[./title/@lang="english"]/runtime'
<runtime>125</runtime>

Upvotes: 3

Related Questions