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

Re: XSL and Javascript to set new window parameters

Subject: Re: XSL and Javascript to set new window parameters
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Nov 2000 10:26:10 +0000
xsl open new window
Phil,

> I have an XSL sheet that constructs a simple table with links created from a
> set of ID's taken from the XML.
> Creating the link is straighforward but I want to ensure that the link is
> opened in a new window with specific parameters.  I know how to do this in
> Javascript using the code
>
> onClick="window.open('default.html','new','toolbars=no,scrollbars=no')

So you want an 'a' element with a 'onclick' attribute with a value of:

  window.open('document.asp?id={@id}&amp;level=1&amp;prodId=news',
              'new', 'toolbars=no,scrollbars=no')

Where the {@id} is the 'id' attribute of the current node from within
the XML.

There are two ways that you can set the value: one is using
xsl:attribute and one is using attribute value templates. From the
examples that you gave, it's clear you have a gap in your
understanding about xsl:attribute.  You use it like:

  <xsl:attribute name="target">_blank</xsl:attribute>

In other words, the name attribute gives the name of the attribute to
be created, and the content of the xsl:attribute element gives the
value of the attribute (the bit in the quotes after the =).

In your case, you want (if you want to use a CDATA section rather than
typing &amp;):

  <xsl:attribute name="onclick">
     <xsl:text>window.open('document.asp?id=</xsl:text>
     <xsl:value-of select="@id" />
     <xsl:text><![CDATA[&level=1&prodId=news]]></xsl:text>
     <xsl:text>', 'new', 'toolbars=no,scrollbars=no')</xsl:text>
  </xsl:attribute>

Whenever you have a value like this that is just a concatenation of
bits of text and xsl:value-ofs, then you can use an attribute value
template instead.  You write the value of the attribute, with the
values of the select attributes of the xsl:value-of bits are included
within {}s:

<a onclick="window.open('document.asp?id={@id}&amp;level=1&amp;prodId=news',
                        'new', 'toolbars=no,scrollbars=no')">
   <xsl:value-of select="." />
</a>

Note that you can't use the CDATA section technique within the
attribute value template, so you have to escape the &s by hand.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.