Chapter 9 — Using Overlays 163
Creating More Detailed Windows from XML and XSLT
The Extensible Stylesheet Language (XSL) provides a method for converting XML data into
different formats through an XSL Transformation (XSLT). Google Maps includes a routine
for formatting XML data through an XSL file into the HTML that is displayed within an info
window. The HTML layout and format can be changed by altering the XSL without making
any changes to the JavaScript. In addition, because the HTML is generated from the XML
generated, the information that is displayed can be extended by adding information to the gen-
erated XML.
The first step toward that process is to generate the XML. For XSL, you normally generate the
XML information where the data is contained within appropriate XML tags. For example, you
might add phone information to the XML with this fragment:
In addition, for your JavaScript-based parser, for ease of extraction you should put the entire
block of XML data into an enclosing tag; for example,infowindow.
Listing 9-11 shows the generation (as a CGI script directly to XML) of suitable data from an
adjusted database table based on the table created earlier in this chapter (Listing 9-7).
Listing 9-11: Creating the XML
#!/usr/bin/perl
use DBI;
use strict;
use CGI qw/:standard/;
print header(-type => ‘text/xml’);
my $dbh = DBI->connect( ‘dbi:mysql:database=mapsbookex;host=db.maps.mcslp.com’,
‘mapsbookex’,
‘examples’,
);
if (!defined($dbh))
{
die “Couldn’t open connection to database\n”;
}
print(“
my $sth = $dbh->prepare(‘select * from ch09_cplx’);
$sth->execute();
while (my $row = $sth->fetchrow_hashref())
Continued