I am using XSLT 1.0. Currently am in <w:t> template. I want to check if the preceding sibling w:r(id=3) has <w:fldChar w:fldCharType="end"/>.
I'm want the immediate preceding sibling only and not w:r having id=2 or id=1.
<t xmlns:w="http://example.com">
<w:r id="1">
<w:fldChar w:fldCharType="start"/>
</w:r>
<w:r id="2">
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:bookmarkStart w:id="0" w:name="tocStartRef_1"/>
<w:r id="3">
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:bookmarkEnd w:id="0"/>
<w:r id="4">
<w:rPr>
<w:rStyle w:val="Span"/>
<w:rFonts w:ascii="arial" w:eastAsia="arial"
w:hAnsi="arial" w:cs="arial"/>
<w:b/>
<w:sz w:val="32"/>
</w:rPr>
<w:t>Fonts</w:t>
</w:r>
</t>
Use the xpath preceding-sibling axis like this:
preceding-sibling::w:r[1]/w:fldChar/@w:fldCharType = 'end'
which will select the nearest ([1]) preceding-sibling named w:r, then descend to any child element(s) named w:fldChar, then any attributes from there named w:fldCharType, then if any such node exists whose text is 'end', returns true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With