Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to match no following sibling

Tags:

xpath

xslt-1.0

Here's my xml,

 <w:tc>
    <w:p>
      <w:pPr></w:pPr>
      <w:r></w:r>
    </w:p>
 </w:tc>
 <w:tc>
    <w:p>
      <w:pPr></w:pPr>
    </w:p>
 </w:tc>

I want to match w:p which is preceded by w:tc and has no following sibling w:r, Precisely i want second w:tc. Code what i have tried,

  <xsl:template match="w:pPr[ancestor::w:p[ancestor::w:tc] and not(following-sibling::w:r)]">

I need xpath for w:pPr having no following-sibling

like image 507
Linda Avatar asked Feb 16 '23 01:02

Linda


1 Answers

The problem is when w:pPr is followed by w:hyperlink. Now i have ignored w:hyperlink too.

If you want to match a w:pPr that has no following sibling elements at all (regardless of name), then just use a match pattern of

w:pPr[ancestor::w:p[ancestor::w:tc] and not(following-sibling::*)]

or equivalently (and slightly shorter)

w:tc//w:p//w:pPr[not(following-sibling::*)]
like image 118
Ian Roberts Avatar answered Mar 21 '23 00:03

Ian Roberts