{
    "mode": "perldoc",
    "parameter": "HTML::Selector::XPath",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3ASelector%3A%3AXPath/json",
    "generated": "2026-06-12T21:16:18Z",
    "synopsis": "use HTML::Selector::XPath;\nmy $selector = HTML::Selector::XPath->new(\"li#main\");\n$selector->toxpath; # //li[@id='main']\n# functional interface\nuse HTML::Selector::XPath 'selectortoxpath';\nmy $xpath = selectortoxpath('div.foo');\nmy $relative = selectortoxpath('div.foo', root => '/html/body/p' );\n# /html/body/p/div[contains(concat(' ', @class, ' '), ' foo ')]\nmy $relative = selectortoxpath('div:root', root => '/html/body/p' );\n# /html/body/p/div",
    "sections": {
        "NAME": {
            "content": "HTML::Selector::XPath - CSS Selector to XPath compiler\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use HTML::Selector::XPath;\n\nmy $selector = HTML::Selector::XPath->new(\"li#main\");\n$selector->toxpath; # //li[@id='main']\n\n# functional interface\nuse HTML::Selector::XPath 'selectortoxpath';\nmy $xpath = selectortoxpath('div.foo');\n\nmy $relative = selectortoxpath('div.foo', root => '/html/body/p' );\n# /html/body/p/div[contains(concat(' ', @class, ' '), ' foo ')]\n\nmy $relative = selectortoxpath('div:root', root => '/html/body/p' );\n# /html/body/p/div\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "HTML::Selector::XPath is a utility function to compile full set of CSS2 and partial CSS3\nselectors to the equivalent XPath expression.\n\nFUNCTIONS and METHODS\nselectortoxpath\n$xpath = selectortoxpath($selector, %options);\n\nShortcut for \"HTML::Selector::XPath->new(shift)->toxpath(@)\". Exported upon request.\n\nnew\n$sel = HTML::Selector::XPath->new($selector, %options);\n\nCreates a new object.\n\ntoxpath\n$xpath = $sel->toxpath;\n$xpath = $sel->toxpath(root => \".\"); # ./foo instead of //foo\n\nReturns the translated XPath expression. You can optionally pass \"root\" parameter, to\nspecify which root to start the expression. It defaults to \"/\".\n\nThe optional \"prefix\" option allows you to specify a namespace prefix for the generated\nXPath expression.\n",
            "subsections": []
        },
        "SUBCLASSING NOTES": {
            "content": "parsepseudo\nThis method is called during xpath construction when we encounter a pseudo selector\n(something that begins with comma). It is passed the selector and a reference to the string\nwe are parsing. It should return one or more xpath sub-expressions to add to the parts if\nthe selector is handled, otherwise return an empty list.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "CSS SELECTOR VALIDATION\nThis module doesn't validate whether the original CSS Selector expression is valid. For example,\n\ndiv.123foo\n\nis an invalid CSS selector (class names should not begin with numbers), but this module ignores\nthat and tries to generate an equivalent XPath expression anyway.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Tatsuhiko Miyagawa 2006-2011\n\nMax Maischein 2011-\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Tatsuhiko Miyagawa <miyagawa@bulknews.net>\n\nMost of the logic is based on Joe Hewitt's getElementsBySelector.js on\n<http://www.joehewitt.com/blog/2006-03-20.php> and Andrew Dupont's patch to Prototype.js on\n<http://dev.rubyonrails.org/ticket/5171>, but slightly modified using Aristotle Pegaltzis' CSS\nto XPath translation table per <http://plasmasturm.org/log/444/>\n\nAlso see\n\n<http://www.mail-archive.com/www-archive@w3.org/msg00906.html>\n\nand\n\n<http://kilianvalkhof.com/2008/css-xhtml/the-css3-not-selector/>\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "<http://www.w3.org/TR/REC-CSS2/selector.html> <http://use.perl.org/~miyagawa/journal/31090>\n<https://en.wikibooks.org/wiki/XPath/CSSEquivalents>\n",
            "subsections": []
        }
    },
    "summary": "HTML::Selector::XPath - CSS Selector to XPath compiler",
    "flags": [],
    "examples": [],
    "see_also": []
}