XPath - How to extract a specific piece of text from a single node text

I would like to extract only part of the text from td, for example "FLAC". How can this be done using XPath?

I tried // text () [contains (., 'FLAC')], but it returns me all the text.

                    <tr>
                        <td class="left">Format plikΓ³w</td>
                        <td>
                                                                AVI, FLV, RM, RMVB, FLAC, APE, AAC, MP3, WMA, OGG, BMP, GIF, TXT, JPEG, MOV, MKV, DAT, DivX, XviD, MP4, VOB
                                                        </td>
                    </tr>
+3
source share
1 answer

First you need to indicate where in your tree, and since you have several elements <td>, you first want to find the node containing the text.

substring(//tr/td[contains(@class, 'left')]/following-sibling::text()[1], startIndex, length)

or

substring(//tr/td[@class='left']/following-sibling::text()[1], startIndex, length)

Update according to comments:

T / P contains (// tr / td [@ class = 'left'] / next-sibling :: text () [1], 'FLAC')

T/F sibling, FLAC. substring() , . , XSLT, / . , !

2

substring('FLAC',1,4*contains(//tr/td[@class='left']/following-sibling::text()[1], 'FLAC'))

FLAC, FLAC node, , , ....

:

  • //tr/td[@class='left'] - ALL <td> , "class" "left"

  • /following-sibling::text() - node .

  • [1] node .

  • (Value, 'FLAC') TRUE ( 1 ), "FLAC" , False (0), .

  • ('FLAC', 1,4 * aboveValue) If/Then/Else XPath 1.0, : "FLAC" , 1,4 * (true = 1) = 4, . "FLAC" , 1,4 * (false = 0) = 0, .

: contains() , , "flac", false. FLAC, translate(), .

+6

All Articles