James Swallow
James Swallow

Reputation: 13

Xpath implementation in Google Sheets

Xpath newbie question, so forgive me if this seems straight forward, but I really have looked everywhere for the answer!

I'm trying to build a process for extracting all my playlists from Spotify and making it universal, allowing migration across various platforms. I will gladly share once completed as I know many people would find this useful.

I'm unfortunately stumped on trying to extract some data from:

[http://musicbrainz.org/ws/2/artist/?query=%22faith%20no%20more%22][1]

I am looking to extract the id from the artist element, which should be b15ebd71-a252-417d-9e1c-3e6863da68f8. I can get this working in Base X with the following:

declare namespace mmd="http://musicbrainz.org/ns/mmd-2.0#";

declare variable $doc := doc("http://musicbrainz.org/ws/2/artist/?query=%22faith%20no%20more%22"); $doc/mmd:metadata/mmd:artist-list/mmd:artist/@id

However, in Google Sheets using Importxml, the best I can do is:

=IMPORTXML("http://musicbrainz.org/ws/2/artist/?query=%22faith%20no%20more%22","//@id")

This results in all 3 id results being returned:

b15ebd71-a252-417d-9e1c-3e6863da68f8 489ce91b-6658-3307-9877-795b68554c98 83f22bb6-4631-443c-bace-9fae8540362a

I am completely stumped and any help will be greatly appreciated.

Kind regards,

James

Upvotes: 1

Views: 108

Answers (1)

Michael Kay
Michael Kay

Reputation: 163332

I haven't been able to find any useful documentation on Google's IMPORTXML, but there is no evidence that it provides any way to establish a namespace binding, or that it supports the XPath 2.0 syntax *:metadata to select elements independent of namespace. If that's the case then you may need to resort to the horrible construct *[local-name()='metadata']/*[local-name()='artist-list']/*[local-name()='artist']

Upvotes: 2

Related Questions