Как использовать starts-with (), contains () и ends-with () в XPath для поиска узла xml innertext? в XPATH 1.0

<ArticleBackmatter>
   <Heading>Ethical standards and patient consent</Heading>
   <Heading>Ethical standards and patient</Heading>
   <Heading>standards and patient consent</Heading>
</ArticleBackmatter>

Я хочу получить внутренний текст, начиная с "этического", содержит " и "и заканчивается" согласием " в узле заголовка.

1 ответов


один из возможных путей:

//Heading[starts-with(., 'Ethical') and ends-with(., 'consent')]

на ends-with() функция XPath 2.0. В XPath 1.0, его можно заменить используя substring() и string-length(). Вот эквивалент XPath 1.0 (обернутый для удобочитаемости):

//Heading[
            starts-with(., 'Ethical') 
                and 
            'consent' = substring(., string-length(.) - string-length('consent') +1)
         ]