Subject: Re: XSL and Javascript to set new window parameters From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Fri, 10 Nov 2000 10:26:10 +0000 |
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}&level=1&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 &): <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}&level=1&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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
XSL and Javascript to set new windo, Phil Davies | Thread | Re: XSL and Javascript to set new w, Robert Koberg |
RE: Question regarding XSL, Kay Michael | Date | RE: Using client side XSLT to creat, Kay Michael |
Month |