Only the immediate preceding brother approaches in xslt

I am using XSLT 1.0. I am currently in the template <w:t>. I want to check if the previous brother has w:r(id=3) <w:fldChar w:fldCharType="end"/>.

I only need the previous sibling, not w:rone with id=2or 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>
+5
source share
1 answer

Use the xpath axis preceding-siblingas follows:

preceding-sibling::w:r[1]/w:fldChar/@w:fldCharType = 'end'

which will select the nearest ( [1]) preceding-siblingwith a name w:r, then go down to any child element (s) with a name w:fldChar, then any attributes from there will be named w:fldCharType, then if any such node exists, the text of which 'end'returns true.

+11

All Articles