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

> 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="'default.html','new','toolbars=no,scrollbars=no')

So you want an 'a' element with a 'onclick' attribute with a value of:'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:value-of select="@id" />
     <xsl:text>', 'new', 'toolbars=no,scrollbars=no')</xsl:text>

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="'document.asp?id={@id}&amp;level=1&amp;prodId=news',
                        'new', 'toolbars=no,scrollbars=no')">
   <xsl:value-of select="." />

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 Tennison

 XSL-List info and archive:

Current Thread