I have an xml file with some content like the following:
<p>
<r>
<t xml:space="preserve">Reading is easier, </t>
</r>
<r>
<fldChar fldCharType="begin"/>
</r>
<r>
<instrText xml:space="preserve"> REF _Ref516568558 \r \p \h </instrText>
</r>
<r>
<fldChar fldCharType="separate"/>
</r>
<r>
<t>This is all the text I want to capture</t>
</r>
<r>
<fldChar fldCharType="end"/>
</r>
<r>
<t xml:space="preserve">, in the new Reading view </t>
</r>
<r>
<fldChar fldCharType="begin"/>
</r>
<r>
<instrText xml:space="preserve"> REF _Not516755367 \r \h </instrText>
</r>
<r>
<fldChar fldCharType="separate"/>
</r>
<r>
<t>But not this...</t>
</r>
<r>
<fldChar fldCharType="end"/>
</r>
<r>
<t xml:space="preserve"> Some other text... </t>
</r>
</p>
I know that I can use the XPath expression //instrText[contains(text(), '_Ref')]
to get <instrText xml:space="preserve"> REF _Ref516568558 \\r \\p \\h </instrText>
.
Now what I want to get is the text within t
nodes between <fldChar fldCharType="begin"/>
and <fldChar fldCharType="end"/>
if between these two tags there is a instrText
with text that contains '_Ref'
ie instrText[contains(text(), '_Ref']
.
Based on this, from the example xml, I would expect only: <t>This is all the text I want to capture</t>
to be returned.
Can this be done with a single XPath 1.0 expression?
试试这个: p/r[preceding-sibling::r[fldChar/@fldCharType='begin'] and following-sibling::r[fldChar/@fldCharType='end']]/t[contains(., '_Ref')]
这就是我最终使用的内容: //p/r[preceding-sibling::r[fldChar/@fldCharType='begin'] and following-sibling::r[fldChar/@fldCharType='end']][instrText[contains(text(), '_Ref')]]/following-sibling::r[t][1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.