Here's my problem:
<xsl:template match="/category">
....
<script
type="text/javascript">
<![CDATA[
if (GBrowserIsComp atible())
{
var map = new GMap(document.g etElementById(" mapdiv"));
map.addControl( new GSmallMapContro l());
map.addControl( new GMapTypeControl ());
map.centerAndZo om(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">m arker<xsl:value-of
select="positio n()"/></xsl:variable>
<xsl:variable name="url">"/pres/story/article_<xsl:va lue-of
select='normali ze-space(@article) '/>.html"</xsl:variable>
<xsl:variable name="title">"< xsl:value-of
select="normali ze-space(title)"/>"</xsl:variable>
<xsl:variable name="created"> "<xsl:apply-templates
select='created '/>"</xsl:variable>
<xsl:apply-templates select="locatio n"/>
var <xsl:value-of select="$marker "/> =
createMarker(po int, <xsl:value-of select="$url"/>,
<xsl:value-of select='$title'/>,
<xsl:value-of select="$create d"/>);
map.addOverlay( <xsl:value-of select="$marker "/>);
</xsl:template>
<xsl:template match="location ">
point = new GPoint( <xsl:value-of select="@longit ude"/>,
<xsl:value-of select="@latitu de"/>);
</xsl:template>
The data is here:
<URL:http://www.weft.co.uk/withmapsdemo/primitive?categ ory=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.9488888888888 9, 54.948888888888 9);
var marker1 =
createMarker(po int, "/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.getDocument Element().norma lize();
(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.9488888888888 9
,
54.948888888888 9
);
var
marker1
=
createMarker(po int,
"/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.o rg.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; this is not a .sig