Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accesing only immediate preceding sibling in xslt

Tags:

xslt

xpath

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>
like image 829
vignesh Avatar asked Feb 11 '11 06:02

vignesh


1 Answers

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.

like image 99
Jeffrey Hantin Avatar answered Sep 25 '22 22:09

Jeffrey Hantin