//div[@class="here"]
is short for
/descendant::div[@class="here"]
The leading "/" means the root. Since you want a relative path rather than an absolute path, what you want is
descendant::div[@class="here"]
In this case,
child::div[@class="here"]
would also do, and that can be abbreviated to
div[@class="here"]
detach and clone work because the detached/cloned element becomes the root of the detached/cloned tree. In that situation, there is no difference between a relative path an an absolute path. However, they are needlessly expensive, they prevent you from looking at the node's ancestors (since you removed them) and detach destroys the tree. I wouldn't use either of those solution.
In reply to Re: HTML and Xpath
by ikegami
in thread HTML and Xpath
by way
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |