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

Re: document.write & copy-of

Subject: Re: document.write & copy-of
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 26 Oct 2000 17:32:26 +0100
document.write table
Lee,

>	<xsl:element name="A">
>		<xsl:attribute name="href">
>
javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,dependent=1,heig
ht=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,toolbar=0,wi
dth=590,resizable=0');
>			Popup.focus();
>			Popup.document.write('
>			<TABLE>
>			<xsl:copy-of select="tr"/>
>			</TABLE>
>			');
>		</xsl:attribute>
>			Enlarge this table
>	</xsl:element>

If you look at the code above, you'll see that you're setting the @href
attribute on the generated A element to a string inside which (as far as
the XSLT processor's concerned) you're creating a TABLE element, and a
number of copies of other elements as well.

XSLT processors justifiably won't let you put elements within attribute
content: you have to escape the < and >.  This means that you can't simply
copy the tr elements across - you have to output them as serialised XML.  I
wrote this template earlier today for a similar problem:

<xsl:template match="*" mode="serialise">
  <xsl:text />&lt;<xsl:value-of select="name()" />
  <xsl:for-each select="@*">
    <xsl:text> </xsl:text>
    <xsl:value-of select="name()" />
    <xsl:text />="<xsl:value-of select="." />"<xsl:text />
  </xsl:for-each>
  <xsl:text>&gt;</xsl:text>
  <xsl:apply-templates mode="serialise" />
  <xsl:text />&lt;/<xsl:value-of select="name()" />&gt;<xsl:text />
</xsl:template>

So, you can either replace the above with:

	<xsl:element name="A">
		<xsl:attribute name="href">

javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,dependent=1,heig
ht=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,toolbar=0,wi
dth=590,resizable=0');
			Popup.focus();
			Popup.document.write('
			&lt;TABLE&gt;
			<xsl:apply-templates select="tr" mode="serialise" />
			&lt;/TABLE&gt;
			');
		</xsl:attribute>
			Enlarge this table
	</xsl:element>

Or you can use CDATA sections so that you don't have to worry about
escaping the < and > around the TABLE element:

	<xsl:element name="A">
		<xsl:attribute name="href">

<![CDATA[javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,depende
nt=1,height=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,too
lbar=0,width=590,resizable=0');
			Popup.focus();
			Popup.document.write('
			<TABLE>]]>
			<xsl:apply-templates select="tr" mode="serialise" />
			<![CDATA[</TABLE>
			');]]>
		</xsl:attribute>
			Enlarge this table
	</xsl:element>

The resultant output will be:

<A
href="javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,dependent=
1,height=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,toolba
r=0,width=590,resizable=0');
	Popup.focus();
	Popup.document.write('
	&lt;TABLE&gt;
	&lt;tr&gt;...&lt;/tr&gt;
	&lt;/TABLE&gt;
	');">Enlarge this table</A>

but the Javascript processor will see the unescaped string:

javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,dependent=1,heig
ht=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,toolbar=0,wi
dth=590,resizable=0');
	Popup.focus();
	Popup.document.write('
	<TABLE>
	<tr>...</tr>
	</TABLE>
	');

and therefore 'do the right thing'.  Or should, anyway.

I hope that this 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.