lxml と xpath を使用して、epub3、xhtml コンテンツ ファイルを解析しています。
たとえば li
、属性を持つすべてのノードを選択したいepub:type="footnote"
<li epub:type="footnote" id="fn14"> ... </li>
適切な xpath 式が見つかりません。
表現
//*[self::li][@id]
属性IDを持つすべてのli
ノードを選択しますが、試してみると
//*[self::li][@epub:type]
エラーが発生します
lxml.etree.XPathEvalError: Undefined namespace prefix
XML は
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="stylesheet.css" />
</head>
<body>
<section class="footnotes">
<hr />
<ol>
<li id="fn1" epub:type="footnote">
<p>See foo</p>
</li>
</ol>
</section>
</body>
</html>
正しい表現の書き方について何か提案はありますか?