While looking at this node, I thought to myself instead of trying to parse HTML dumped from lynx (possibly error-prone plus requires an external program,) why not use the RDF feed that slashdot provides at http://slashdot.org/slashdot.rdf? And as you would then be converting from one XML DTD to another, isn't this a perfect opportunity to use XSLT? Here's what I came up with:
#!/usr/bin/perl -w use strict; # # A script to convert slashdot headlines to VXML. # (C) 2001, Jaldhar Vyas # Licensed under the Crowley Public License ("Do what thou wilt # shall be the whole of the license.") # use LWP::Simple qw(get); use XML::LibXML; use XML::LibXSLT; my $content = get('http://slashdot.org/slashdot.rdf'); unless (defined ($content)) # undef means something went wrong. { $content = <<'-EOT-'; <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <item> <title>Failed to retrieve headlines</title> </item> </rdf:RDF> -EOT- } my $xml = XML::LibXML->new(); my $xslt = XML::LibXSLT->new()->parse_stylesheet($xml->parse_fh(*DATA) +); print "Content-type: text/xml\n\n" , $xslt->output_string($xslt->transform($xml->parse_string($content))) +; __DATA__ <?xml version="1.0"?> <xsl:stylesheet xmlns="" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rss="http://my.netscape.com/rdf/simple/0.9/"> <xsl:namespace-alias stylesheet-prefix="#default" result-prefix='rss +' /> <xsl:output method="html" media-type="text/xml" indent="yes" /> <xsl:template match="rdf:RDF"> <vxml version='2.0'> <form><block> <xsl:apply-templates select="rss:item/rss:title" /> </block></form> </vxml> </xsl:template> <xsl:template match="rss:title"> <xsl:value-of select="." /><xsl:text>. </xsl:text> </xsl:template> </xsl:stylesheet>
A problem I ran into was due to XML namespaces. RDF is built on the older RSS spec and most of the tags are actually declared in the RSS namespace. Other than that it was fairly simple and should be a lot more maintainable in the long run.

In reply to Sounds like a job for XSLT (tan-tan-tan-tan-tanaaa!) by jaldhar
in thread Slashdot over the phone by beretboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.