Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 6th, 2008, 08:50 PM
Registered User
 
Join Date: Dec 2008
Location: st louis, , .
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


Reply With Quote
  #2 (permalink)  
Old December 7th, 2008, 05:10 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 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
Reply With Quote
  #3 (permalink)  
Old December 7th, 2008, 03:31 PM
Registered User
 
Join Date: Dec 2008
Location: st louis, , .
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.
Reply With Quote
  #4 (permalink)  
Old December 7th, 2008, 06:57 PM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 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
Reply With Quote
  #5 (permalink)  
Old December 11th, 2008, 10:23 PM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:49 PM



All times are GMT -4. The time now is 07:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.