Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2008, 09:50 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default newbie question (javascript passed in xml)

Very new to xslt . We have one xsl sheet that handles processing of many different xml documents into html. We'd like to include custom javascript on the html rendered output. Since there is only one xslt, the xml source has a CDATA section where the custom javascripts are included.

<my xml>
<![CDATA[<script>alert('this does not alert when the page is rendered even though it is in the html source')</script>]]>

<morexml />
</my xml>

The scripts are being rendered out and we can view them in the html source, but they don't appear to work.

Is this even possible?
Thanks in advance


 
Old December 7th, 2008, 06:10 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Why the CDATA? CDATA means "the stuff in here is not markup, even if it looks like markup". So the HTML output is going to contain &lt;script&gt; rather than <script>, which means the browser will not recognize it. The CDATA appears to achieve nothing here other than to deactivate the script element.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old December 7th, 2008, 04:31 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Apologies...looks like I typo'd.. it actually looks like this:
<my xml>
<script><![CDATA[<alert('this does not alert when the page is rendered even though it is in the html source')]]></script>

<morexml />
</my xml>

The xslt looks for //script and outputs this in the html.

<script language="javascript">
alert('this does not alert when the page is rendered even though it is in the html source');
</script>
it never actually fires though.
 
Old December 7th, 2008, 07:57 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks like you have an HTML problem rather than an XSLT problem.

Create an HTML page by hand that has the effect you want; then try to write XSLT code to generate the equivalent HTML.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old December 11th, 2008, 11:23 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Delete the < character present before the word "alert" in the below script.

<script><![CDATA[<alert('this does not alert when the page is rendered even though it is in the html source')]]></script>
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to passed an xsl parameter to a javascript fun jadeite100 XSLT 1 June 22nd, 2007 02:51 PM
Newbie question savoym JSP Basics 1 August 16th, 2006 03:15 AM
newbie question Warbird XML 0 May 11th, 2005 08:41 AM
Newbie - Javascript Mizman Classic ASP Databases 1 January 27th, 2005 02:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.