Skip to content

feat: add Shadow DOM support for XPath queries#682

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

feat: add Shadow DOM support for XPath queries#682
xjasonli wants to merge 1 commit intoFontoXML:masterfrom
xjasonli:feat-shadowroot

Conversation

@xjasonli
Copy link

@xjasonli xjasonli commented Jan 9, 2026

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
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
Copy link
Author

xjasonli commented Feb 7, 2026

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!

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

2 participants

Comments