How to write this xpath request?

I use rss from several sites, and my real problem is with their Pubdate field, because most of their PubDate values ​​are invalid, since I manage to get the value from the PubDate field set using xpath. this is what i wrote:

//item/title | 
//item/description | 
//item/link | 
//item/pubDate | 
//item/category

and I want to limit my result to 10 with the latest news that I know in xpath, we have a postion () function, and I have to use it as shown below:

[postion() <= 10]

but when I mix these two xpath requests together, I will not get the correct result:

 //item/title | 
 //item/description | 
 //item/link | 
 //item/pubDate | 
 //item/category [position() <= 10]

how can I write this particular xpath request in the correct format. and is there any high speed book for xpath?

regads.

+3
source share
3 answers

I guess the latest news is upstairs.

Using

(//item)[not(position() > 10)]/*
           [self::title or self::description 
           or self::link or self::pubDate or self::category
           ]

title, description, link, pubDate category, 10 item XML.

, ( , item):

//item[1]

item , , item.

XPath, item :

(//item)[1]

. [] ( ), //.

+4

10

/descendant::item[
   10 > last()-position()
]/*[
   self::title|self::description|self::link|self::pubDate|self::category  
]
+2

//item[position() <= 10]/pubDate

, 10- !

0

Source: https://habr.com/ru/post/1791991/


All Articles