Skip to content

feat: add DocumentFragment support for XPath queries#682

Open
xjasonli wants to merge 1 commit into
FontoXML:masterfrom
xjasonli:feat-shadowroot
Open

feat: add DocumentFragment support for XPath queries#682
xjasonli wants to merge 1 commit into
FontoXML:masterfrom
xjasonli:feat-shadowroot

Conversation

@xjasonli

@xjasonli xjasonli commented Jan 9, 2026

Copy link
Copy Markdown

Support DOCUMENT_FRAGMENT_NODE (ShadowRoot) as valid root for XPath expressions. Includes namespace resolution fallback to host element since ShadowRoot.lookupNamespaceURI returns null.

Fix: #681

@DrRataplan

Copy link
Copy Markdown
Contributor

Thanks for the PR! Just looking through it. It's a tricky one, since the XQuery DOM has no notion of document fragments. I do agree fontoxpath can just treat them as document nodes, with multiple children. No harm in that.

A test or two would be really useful here. Slimdom has support for document fragments, which is I think the gist of this PR: supporting document fragments. A test for the sibling axis might be specifically interesting: creating a document fragment with two elements, and addressing the second one from the first with following-sibling::element(). Should work.

Can we rename the commits to supporting Document Fragments? I first thought we were implementing going from a shadow host into its shadowroot, exposing the shadowroot as a child of its host. Not sure if we want that.

KR,

Martin

@xjasonli

xjasonli commented Feb 7, 2026

Copy link
Copy Markdown
Author

Hi Martin

Thanks for the suggestions!

I just force-pushed the updates. I added some tests for document fragments, and the sibling axis one is working great. I also renamed the commit to "Support document fragments as root/context node" to keep things clear.

Let me know what you think!

@xjasonli xjasonli changed the title feat: add Shadow DOM support for XPath queries feat: add DocumentFragment support for XPath queries Feb 27, 2026
@xiaoyu066

Copy link
Copy Markdown

This change is very helpful to me.

@xjasonli

xjasonli commented Jul 3, 2026

Copy link
Copy Markdown
Author

Thanks for the review and approval, @DrRataplan !

It seems GitHub still requires a review from an account with active write permissions to unblock the merge. Could any maintainer help take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ShadowRoot (DocumentFragment) as a valid context node in browser environments

3 participants