[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Javascript : from xsl to xml

Subject: Re: Javascript : from xsl to xml
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 03 Aug 2000 20:56:28 +0100
javascript window.open xml
Michel,

>2. I have this Javascritp in my xsl :
>
><script language="JavaScript">
><![CDATA[function image(){
>         window.open('  NOT YET DEFINED ');
>}
>]]>
></script>
>
>I would like to know how to make the method "WINDOW.OPEN" work with a 
>variable that would get the information which is stored in the IMAGE 
>element of my xml, so putting the image in the opening window. I will have 
>340 different xml pages, one for each expression of the encyclopedia.

>From what I gather, you are generating this script element as part of the
output HTML from a stylesheet.  Just as with any other output that you
generate within an XSL page, you can insert values of particular XPath
expressions using xsl:value-of.  So if you want the value of the @href
attribute of the IMAGE element, you can use:

  <xsl:value-of select="/ROOT/SEE_PICTURE/IMAGE/@href" />

I'm sure you're aware of this, so I guess that the problem you're having is
inserting this into the javascript.  If you were to simply insert it into
your existing script element like:

<script language="JavaScript">
  <![CDATA[
  function image() {
    window.open('<xsl:value-of select="/ROOT/SEE_PICTURE/IMAGE/@href" />');
  }
  ]]>
</script>

then it would be within a CDATA section, and would thus not be interpreted
as XSLT (or XML for that matter).

Within the XSLT stylesheet, the CDATA section is purely a utility to stop
you from having to escape all the '<' etc. that you would have to
otherwise.  The CDATA section in your XSLT stylesheet does not translate
into a CDATA section in your output.  So your script element translates to:

<script language="JavaScript">
  function image() {
    window.open('  NOT YET DEFINED ');
  }
</script>

as there are no peculiar characters to be escaped within it.  Given that,
you could simply do:

<script language="JavaScript">
  function image() {
    window.open('<xsl:value-of select="/ROOT/SEE_PICTURE/IMAGE/@href" />');
  }
</script>

and the value of the IMAGE's @href will be inserted as an argument.  If
there *are* characters that need to be escaped in your javascript, then
there's no problem just stopping the CDATA section before the piece of XSLT
and then starting it again afterwards:

<script language="JavaScript">
  <![CDATA[
  function image() {
    window.open(']]><xsl:value-of
                      select="/ROOT/SEE_PICTURE/IMAGE/@href" /><![CDATA[');
  }
  ]]>
</script>

I hope that I've understood your problem correctly and that this helps you
solve it.

Cheers,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.