Can Perl's HTML::Selector::XPath be used for the general purpose of finding XPaths?
use HTML::Selector::XPath;
my $selector = HTML::Selector::XPath->new("li#main");
$selector->to_xpath; # //li[@id='main']
# functional interface
use HTML::Selector::XPath 'selector_to_xpath';
my $xpath = selector_to_xpath('div.foo');