如何在XPath中使用starts-with(),contains()和ends-with()来查找xml节点innertext?在XPATH 1.0中

时间:2014-10-06 13:13:21

标签: xslt xpath xpath-1.0

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

我希望从&#34; Ethical&#34;开始获取内部文本。 ,包含&#34;和&#34;并以&#34;同意&#34;结束在标题节点中。

1 个答案:

答案 0 :(得分:26)

一种可能的方式:

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

ends-with()函数是XPath 2.0。在XPath 1.0中,it can be replaced使用substring()string-length()。这是等效的XPath 1.0(为了便于阅读而包装):

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