Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

xslt - How to use starts-with() , contains() and ends-with() in XPath to find the xml node innertext? in XPATH 1.0

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

I want to get the inner text with start from "Ethical" , contains "and " and end with "consent" in the Heading node.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One possible way:

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

The ends-with() function is XPath 2.0. In XPath 1.0, it can be replaced using substring() and string-length(). Here is the equivalent XPath 1.0 (wrapped for readability):

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...