I don’t understand why we should use text() instead of just using “.”
What is the difference?
//library/book/author[text() = "An Author"]
vs
//span[@class="whateverclass"][. = "An Author"]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The difference is probably best illustrated with an example, where an element has one or more child elements, and multiple text elements (an element is allowed multiple text elements interspersed between child elements):
Assuming
elementis current:.will returntext1 child1text1 text2(with whitespace)text()[1]will returntext1text()[2]will returntext2Of special note is
text()will behave differently in xslt 1.0 vs xslt 2.0text()returns justtext1in xslt 1.0text()returnstext1 text2(with whitespace) in xslt 2.0