Hi,<br><br>I am writing a www bot that gets xml from a website that includes a xsl stylesheet to apply to the xml to give html. Browsers seem to do this for us when browsing the site. WWW::Mechanize does not seem to. I wrote some code but hit a conundrum. How do I get the url of the xsl from the xml content, fetch it via http and apply it to the xml using XML::LibXSLT?<br>
<br>Hi, Thanks for the reply. I realized that I need libxslt. But unless I am missing something I don't see how to pull the xsl uri out of the xml and feed it to libxslt (XML::LibXSLT). That is my problem.<br><br>the xml starts with:<br>
<br><?xml version="1.0" encoding="UTF-8"?><br><?xml-stylesheet type="text/xsl" href="/something.xsl"?><br><br><page><br><br>...<br><br></page><br><br>Maybe I should just grep through the xml to find the stylesheet? Maybe I feed XML::LibXSLT a URL? Maybe I just feed the xml to XML::LibXSLT and it fetches the XSL stylesheet automagically? I don't know. I have not been able to figure out more than what I have below from the docos and examples.<br>
<br>Can you help me? Thanks, Ben Marsh <br><br>Here is my code:<br><code><br>use lib qw|/home/blm/perl/lib|;<br><br>use strict;<br><br>use WWW::Mechanize;<br>use XML::LibXML;<br>use XML::LibXSLT;<br><br>my $mech = WWW::Mechanize->new(agent => 'Mozilla/5.0 (X11; U; Linux i686; en-US;+ rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1' );<br>
<br>my $url = '<a href="https://some.url.here/">https://some.url.here/</a>';<br>$mech->delete_header('accept-encoding');<br>$mech->get($url);<br><br>$mech->update_html($mech->content());<br><br>
print $mech->content;<br>my $parser = XML::LibXML->new();<br>my $style_parser = XML::LibXML->new();<br>my $xslt = XML::LibXSLT->new();<br><br>my $doc = $parser->parse_string($mech->content());<br>print $doc->toString();<br>
my $stylesheet_location = ***Here is my problem***<br>$mech->get($stylesheet_location);<br>my $stylesheet_string = $mech->content();<br>my $styledoc = $style_parser->parse_string($stylesheet_string);<br>
my $stylesheet = $xslt->parse_stylesheet($styledoc);<br>my $results = $xslt->transform($doc);<br>print $results;<br>