samedi 18 octobre 2014

Attributes in Xpath local-name()


Vote count:

0




This is a small sample of my xml file.



<w:p><w:pPr><w:rPr><w:highlight w:val="yellow"/></w:rPr></w:pPr><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r w:rsidRPr="00D1434D"><w:rPr><w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman"/><w:b/><w:color w:val="000000"/><w:sz w:val="24"/><w:szCs w:val="24"/><w:highlight w:val="yellow"/></w:rPr><w:t xml:space="preserve">Responses to </w:t></w:r><w:r w:rsidR="00335D4A" w:rsidRPr="00D1434D"><w:rPr><w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman"/><w:b/><w:color w:val="000000"/><w:sz w:val="24"/><w:szCs w:val="24"/><w:highlight w:val="yellow"/><w:lang w:eastAsia="ja-JP"/></w:rPr><w:t>the Reviewer</w:t></w:r>


I want to extract text with the w:highlight tag specifically having the attribute value = "yellow" . I searched for it but wasn't able to come up with a solution.


The following works for highlight in general:



for t in source.xpath('.//*[local-name()="highlight"]/../..//*[local-name()="t"]'):
do something


I tried :



for t in lxml_tree.xpath('//*[local-name()="highlight"][@val="yellow"]/../..//*[local-name()="t"]'):


this doesn't work, returns nothing..



asked 1 min ago

Swordy

478






Attributes in Xpath local-name()

Aucun commentaire:

Enregistrer un commentaire