生成CDATA部分......? [英] Generating CDATA sections...?

查看:86
本文介绍了生成CDATA部分......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:


< xsl:template match =" / category">

....

< script

type =" text / javascript">

& lt;![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(我们很抱歉,但

Google Maps不支持您的浏览器);

}

]]& gt;

< / script>

....

< / xsl:template>


<! - 请勿重新格式化。 CDATA,JavaScript

和XSL之间的互动非常糟糕! - >

< 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 ='''创建''/>"< / xsl:variable>

< xsl:apply-templates select =" location" />

var< xsl:value-of select =" $ marker" /> =

createMarker(点,< 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>


数据在这里:

< URL:http://www.weft.co.uk/withmapsdemo/primitive?category = 9>


那么什么问题是什么?


好​​吧,如果你从命令行运行它,例如


- [simon] - > xsltproc pres-news-map.xsl primitive.xml


它工作正常,你得到这个:

< URL:http://www.weft .co.uk / withmapsdemo / demo.html>

(是的,这是一个轻微的JavaScript错误,但我不是太困扰

刚才);关键位格式化


point = new GPoint(-3.94888888888889,54.9488888888889);


var marker1 =

createMarker(点,/pres/story/article_64.html" ;,

Gareth'关闭到Land Down Under',2006年1月13日星期五);


map.addOverlay(marker1);


但是如果你在服务器端运行它,就像我通常那样,你会回到DOM

树不是一个大的CDATA节点,而是一系列的Text节点,即使你这样做也是如此。
doc.getDocumentElement()。normalize();


(我这样做)。因为它是Text而不是CDATA,

中的XML语法字符在打印时得到了证实,你得到:


point = new GPoint(

-3.94888888888889



54.9488888888889

);

var

marker1

=

createMarker(点,

& quot; /pres/story/article_64.html& quot;



& quot; Gareth's off to a Land Down Under& quot;



& quot ; 2006年1月13日星期五& quot;

);


map.addOverlay(

marker1

);


,JavaScript引擎完全不认识为JavaScript。


最后,如果你运行转换XML客户端(如果你使用浏览器转到< http://www.weft.co.uk/withmapsdemo/newsmap>
$ b $,你会做什么?
b在其Accepts标题中发送text / xml或application / xml),

你得到(或者至少我这样做,绝对没有任何东西。


关于我错了什么的想法,以及我如何解决这个问题?


-
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/


;;这不是.sig

解决方案

marker" /> =

createMarker(点,< xsl:value-of select ="


url" />,

< ; xsl:value-of select =''


title''/>,

< xsl:value-of select ="

Here''s my problem:

<xsl:template match="/category">
....
<script
type="text/javascript">
&lt;![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");
}
]]&gt;
</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,
&quot;/pres/story/article_64.html&quot;
,
&quot;Gareth's off to a Land Down Under&quot;
,
&quot;Friday, 13 January, 2006&quot;
);

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

解决方案

marker"/> =
createMarker(point, <xsl:value-of select="


url"/>,
<xsl:value-of select=''


title''/>,
<xsl:value-of select="


这篇关于生成CDATA部分......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆