use XML::XSLT;
use LWP::Simple;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
my $xsl = get("blog2.xsl")
my $xslt = XML::XSLT->new ($xsl, warnings => 1, base => "/home/bosshof
+f/www/blog/");
my $xml = get("posts.xml")
$xslt->transform ($xml);
print $xslt->toString;
$xslt->dispose();
blog2.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Tr
+ansform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:output doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-tra
+nsitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<style type="text/css">
@import url("main.css");
</style>
</head>
<body>
<xsl:call-template name="topMenu"/>
</body>
</html>
</xsl:template>
<xsl:template name="topMenu">
<div id="topMenu">
<xsl:for-each select="document('menu.xml')/menu/item">
<span class="topMenu">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="href"/></
+xsl:attribute>
<xsl:value-of select="name"/>
</xsl:element>
</span>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
posts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<posts>
<post title="Setting Up Gentoo" date="2005-2-24" id="1">
<para firstLetter="T">he kernel I'll be going with is 2.6.10-gentoo-r6
+, which is the most recent gentoo-enhanced version of the kernel to d
+ate. The stage I've chosen to start from is a Stage 2 install: basic
+ally, all the low-level system stuff is already provided, which I wou
+ld need anyway. No, I'm not yet nuts enough to do a Stage 1. If you
+ are confused about what I'm talking about, please go to <url>http://
+www.gentoo.org/doc/en/handbook/handbook-x86.xml</url>. That is the g
+uide I used to install my system.</para>
<para>Though this server will mostly be used for server operations, I
+would like a window manager to make rooting through configurations ea
+sier. I chose fluxbox (<url>http://fluxbox.sourceforge.net/</url>) f
+or its very small overhead, unlike KDE or Gnome, which insist on inst
+alling a bunch of stuff I won't need (including all that lame GUI con
+fig crap).</para>
</post>
</posts>
menu.xml:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<item>
<name>Home</name>
<href>http://pansy/main.xhtml</href>
</item>
<item>
<name>Somewhere else</name>
<href>#</href>
</item>
</menu>
It won't work unless you comment out the document command and take out the base argument when instantiating the XML::XSLT object. |