473,803 Members | 3,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating CDATA sections...?

Here's my problem:

<xsl:template match="/category">
....
<script
type="text/javascript">
&lt;![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");
}
]]&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">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,
&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.o rg.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; this is not a .sig
Mar 11 '06
10 2354
in message <fq************ @gododdin.inter nal.jasmine.org .uk>, Simon
Brooke ('s****@jasmine .org.uk') wrote:
in message <Ge************ ********@comcas t.com>, Joe Kesselman
('k************ *@comcast.net') wrote:
Slight correction: XSLT treats the as identical on input.

On output, you can use the cdata-section-elements directive of
xsl:output to identify elements whose text content should be wrapped
in CDATA sections.


Ah! Kwa-tcha! Thank you. 'cdata-section-elements="scrip t"' seems to be
a big step towards what I need; you need to use 'method="xml"' as well.
Fixing the serialiser seems to be the rest. I'm still finding that even
after using cdata-section-elements="scrip t" and using
Document.getDoc umentElement(). normalize() the DomImplementati on is
still passing the contents to me as a series of fragmentary text nodes
rather than as a single CDATA node, which means I escape the
contents... Damn. Still, I can make it work with this. Thanks.


On further investigation, all those who said that CDATA had nothing to do
with the case were, of course, perfectly correct. The fundamental
problem is bugs in my serialiser. Which I now need to fix. Bother.

--
si***@jasmine.o rg.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
; ... of course nothing said here will be taken notice of by
; the W3C. The official place to be ignored is on www-style or
; www-html. -- George Lund

Mar 13 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2424
by: Aidan | last post by:
The setup: a Sax parser in a servlet and a Java client (same machine) which uploads an XML document containing CDATA elements which hold base 64 encoded binary files. The servlet then SAX parses the client's data. If I comment out the parser call I can see that the transmition time of large data files is very low. My understanding is that a SAX parser should transmit the content of a CDATA string downstream without signiificant...
0
2060
by: Chris Waddingham | last post by:
I am experiencing 2 problems with CDATA sections. These are: 1. Expat appears to be collapsing adjacent linefeeds into one inside CDATA sections. 2. Expat (XML_CharacterDataHandler) returns the wrong len value for CDATA sections containing ']'. I would be grateful of any help you can offer. My XML application contains code like this:
10
42971
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA attribute values are part of markup or not.) Thanks.
4
2018
by: Jake Barnes | last post by:
I'm reading over this page: http://wiki.script.aculo.us/scriptaculous/show/Usage I'm struck by this code example +++++++++++++++++++++++++++++++ 3. Use
11
6469
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
2
5254
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL reformats the XML to another format (still XML, not HTML). This works fine, but whatever I do, I can't get the finally output section to have CDATA elements. I've added a cdata-section-elements tag into the xsl file, but it doesn't seem to have...
12
4015
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> Is this trick grounded in any real information about HTML vs XHTML? I
3
3170
by: yawnmoth | last post by:
How might I go about including a ]]in a cdata tag? Since ]]>'s normally close cdata's, ]]>, by itself, wouldn't work...
7
5272
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the spitting back out that's giving me issues. The fact that lxml strips all the CDATA stuff off isnt really a big issue either, so long as I can create CDATA blocks later with <>&'s showing up instead of &lt;&gt;&amp; . I've scoured through the lxml docs, but...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.