Ripping out parts of a DOM using XML::XSLT

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hey folks

I have what I think is a simple task but one that I am struggling
I have this KML (Slightly abridged)

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=" " xmlns:gml="http://">
<name>Gazetteer for Scotland</name>
    <name> Troon </name>
    <description>A resort town on the coast of Kyle in Ayrshire, Troon
lies at the north end of Ayr Bay on a headland that extends into the
    <Point id="t476">
    <name> Niall Home </name>
    <description>Not a lovely little home in the western isles
    <Point id="t576">
<ExtendedData xmlns:GforS=" /">
         &lt;p&gt;All Images and Text are Copyright (c) The Gazetteer for
Scotland 1995-2008 &lt;/p&gt;

This KML is generated by a perl script lying on the web and so I am
able to 'get' this KML from the web and parse it into a DOM using the
script below:


use XML::DOM;
use Data::Dumper;
use LWP::Simple;
use XML::DOM::XPath;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

 #Gets the contents of the URLs
my $sg_get = $ua->get(' /

  #Creates instance of new XML::DOM::Parser and uses to make new DOM
my $parser = new XML::DOM::Parser;

  # Parses the contents of the 'got' URL
my $sg_dom = $parser->parse ($sg_get->content);

 #Prints the contents of a DOM::Parsed document to the screen
#print Dumper($sg_dom);

 #Saves the content of the DOM to a file
#$sg_dom->printToFile ("out.kml");


What I would actuallylike to do is use an XSL to pull out only the
Placemarks (including the placemark tags).
The reason for this is that I actually have four of these KML files
and I want to rip out all the Placemarks from each KML and then using
DOM (i know how to) put all the placemarks into one single KML and
serve this out to the user.

So how far have I got?
Well, the XSL file I am using is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl=" ">
<xsl:output method="xml" indent="yes" version="1.0" omit-xml-
declaration ="no"/>

<xsl:template match="/Document/Placemark">
<xsl:for-each select="kml/document/Placemark">
    <name><xsl:for-each select="kml/document/Placemark/name"></name>

As you can see it is only getting the name from each Placemark and it
doesn't work! When using with teh perl script:


use XML::XSLT;
use strict;
use warnings;

my $xsl="xsl.xsl";
my $xml="out.kml";

# Create an instance of XSLT
my $xslt = eval { XML::XSLT->new($xsl, warnings => 1, debug => 0) };

print $xslt->to_dom;

# Free the memory

It says that it cannot create an instance of the XSL! For the moment I
have written my KML to a file to ease things up a little.

So can any of you people help? In the past I have found you all really
helpful and so I hope you can help me with this one! Sorry for the
long post but I wanted to try to get all the info down!



Site Timeline