Here's my problem:
<xsl:template match="/category">
....
<script
type="text/javascript">
<![CDATA[
if (GBrowserIsCompatible())
{
var map = new GMap(document.getElementById("mapdiv"));
map.addControl( new GSmallMapControl());
map.addControl( new GMapTypeControl());
map.centerAndZoom(new GPoint( -4, 55), 8);
<xsl:apply-templates select="//story"/>
}
else
{
alert( "We're sorry, but your browser is not supported by
Google Maps");
}
]]>
</script>
....
</xsl:template>
<!-- DO NOT reformat this. The interaction between CDATA, JavaScript
and XSL is horrible! -->
<xsl:template match="story">
<xsl:variable name="marker">marker<xsl:value-of
select="position()"/></xsl:variable>
<xsl:variable name="url">"/pres/story/article_<xsl:value-of
select='normalize-space(@article)'/>.html"</xsl:variable>
<xsl:variable name="title">"<xsl:value-of
select="normalize-space(title)"/>"</xsl:variable>
<xsl:variable name="created">"<xsl:apply-templates
select='created'/>"</xsl:variable>
<xsl:apply-templates select="location"/>
var <xsl:value-of select="$marker"/> =
createMarker(point, <xsl:value-of select="$url"/>,
<xsl:value-of select='$title'/>,
<xsl:value-of select="$created"/>);
map.addOverlay(<xsl:value-of select="$marker"/>);
</xsl:template>
<xsl:template match="location">
point = new GPoint( <xsl:value-of select="@longitude"/>,
<xsl:value-of select="@latitude"/>);
</xsl:template>
The data is here:
<URL:http://www.weft.co.uk/withmapsdemo/primitive?category=9>
So what's the problem?
Well, if you run it form the command line, e.g.
-[simon]-> xsltproc pres-news-map.xsl primitive.xml
It works OK and you get this:
<URL:http://www.weft.co.uk/withmapsdemo/demo.html>
(yes, there's a minor JavaScript error, but I'm not too bothered about
that just now); the critical bit is formatted
point = new GPoint( -3.94888888888889, 54.9488888888889);
var marker1 =
createMarker(point, "/pres/story/article_64.html",
"Gareth's off to a Land Down Under", "Friday, 13 January, 2006");
map.addOverlay(marker1);
But if you run it server-side, as I usually do, you get back in the DOM
tree not one big CDATA node, but a series of Text nodes, even if you do
doc.getDocumentElement().normalize();
(which I do). Because it's Text and not CDATA, XML syntax characters in
it get entified on printing, and you get:
point = new GPoint(
-3.94888888888889
,
54.9488888888889
);
var
marker1
=
createMarker(point,
"/pres/story/article_64.html"
,
"Gareth's off to a Land Down Under"
,
"Friday, 13 January, 2006"
);
map.addOverlay(
marker1
);
which the JavaScript engines simply don't recognise as JavaScript at all.
Finally, if you run the transform the XML client side (which you will do
if you go to <http://www.weft.co.uk/withmapsdemo/newsmap> with a browser
which sends either text/xml or application/xml in its Accepts header),
you get (or at least I do, with Firefox) absolutely nothing at all.
Any ideas about what I've got wrong, and how I can fix this?
--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; this is not a .sig