[Omaha.pm] [OT] Parsing XML with command line XSLT xsltproc...
Patrick Timmins
ptimmins at cox.net
Fri Feb 5 23:33:00 PST 2010
Tools that understand XSL are ubiquitous ... I sure wouldn't recommend
down-loading or writing some code (Perl or otherwise), and then manually
going through the process of running the RSS through your code, and then
re-loading the output into your player. Foist the work off on the
machines/devices, I say :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/" >
<html>
<body>
<xsl:for-each select="//channel">
<table>
<tr>
<th style="text-align: center;">
<a>
<xsl:attribute name="href">
<xsl:value-of select="link" />
</xsl:attribute>
<xsl:value-of select="title" />
</a>
</th>
</tr>
<tr>
<td style="text-align: center; font-size: smaller;">
Last Updated on <xsl:value-of select="pubDate" />
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
<xsl:for-each select="item">
<tr>
<td style="text-align: left;">
<a>
<xsl:attribute name="href">
<xsl:value-of select="link" />
</xsl:attribute>
<xsl:value-of select="title" />
</a>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="description" disable-output-escaping="yes" />
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSL is your friend. Resistance is futile. You will be assimilated.
:)
Pat
--
Patrick Timmins
ptimmins at cox.net
Dan Linder wrote:
> 2010/2/1 Sterling Hanenkamp <sterling at hanenkamp.com>:
>
>> I hope you'll forgive me, but I'm going to be annoying and not answer your
>> question in the way that you asked. I dislike XSLT, so I'd use:
>> XML::RSS
>> XML::Twig
>> Or something else on CPAN
>>
>
> Completely understood - my only reason for using it is because
> "bashpodder" used it in it's main script and I had a small bit of
> sample XSL code to look at. :-)
>
> I'm always up for trying to solve a problem with a new tool, and in
> this case you're probably right that Perl and/or a CPAN module might
> be the best solution. I'll look into these.
>
>
>> I used to do XSLT, particularly when I was mostly stuck working with Java.
>> Then, (after cutting off my Java) I realized that if I wanted a
>> Turing-complete template language, I already have Perl. Performance is about
>> the same, Perl has more features, and I don't have to use XML to write code.
>>
>
> This is actually my first foray into XSLT. Any XML I've ever
> generated or parsed were from my own home-grown Perl scripts that
> didn't use any CPAN modules... (Thankfully I could control the format
> of the data I was reading so nesting and other text formatting didn't
> affect these tests..)
>
> Thanks,
>
> Dan
>
More information about the Omaha-pm
mailing list