monthname monthname_short

  • 1
  • Question
  • Updated 3 years ago
Hello,

I am new to XPath

Using the forecast10day data, I am trying to pull monthname with this select query:

/forecast/simpleforecast/forecastday/date/monthname

but it returns both monthname data and monthname_short.


Any ideas how I can modify the query to get just the one node?
Photo of Will

Will

  • 2 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
very strange xpath parser behavior...
by a quick online test, I wasn't able to find an xpath processor to reproduce this particular case, so I assume an equivalent "wild" xpath as the following
/response/forecast/simpleforecast/forecastdays/forecastday[1]/date/*[starts-with(name(), 'monthname')]
which returns the dual elements. my applied solution is to wrap the expression in parenthesis and ask just for the first element:
(/response/forecast/simpleforecast/forecastdays/forecastday[1]/date/*[starts-with(name(), 'monthname')])[1]/text()
I also assumed you wanted innertext value, not the node itself
Photo of Will

Will

  • 2 Posts
  • 0 Reply Likes
Thanks for the answer.  I was using Google Sheets' built-in parser.  You gave me a much better frame of reference.