I have a parent element (font) and I would like to select all the child elements (direct descendants) that are either text() or span elements. How would I construct such an xpath?
Share
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.
If the current node is the
fontelement, then something like this:otherwise you have to always combine with
|the two complete XPath – the one for text and the one for span, e.g.:if the current node is just above
font– orif starting from the root with some complex selection criteria.
If you have complex paths like the last one probably it is better to store a partial one in a variable – e.g. inside an XSLT:
Another possibility is to do something like this:
that works because
name()returns an empty string fortext()nodes – but I am not 100% sure that it works that way for all XPath processors, and it could match by mistake comment nodes.