David542
David542

Reputation: 110267

lxml startswith for xpath

How would I get the following (using the % for a LIKE statement) --

assets['HasEN'] = self.node.xpath('//data_file[@role="source"]/locale[@name="en%"]')

In other words, the name could be en, it could be en-US, it could be en-GB, etc.

Is there a way to do that with lxml or do I have to do that after parsing the XML?

Upvotes: 6

Views: 4397

Answers (1)

David542
David542

Reputation: 110267

You can use this syntax:

/locale[starts-with(@name, "en")]

Upvotes: 10

Related Questions