Re: document.write & copy-of

Subject: Re: document.write & copy-of
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 26 Oct 2000 09:14:03 -0600 (MDT)
Lee Goddard wrote:
> 		<xsl:attribute name="href">
> 			javascript:Popup=window.open('','IntlPopup','alwaysRaised=1,dependent=1,height=300,location=0,menubar=1,personalbar=0,scrollbars=0,status=0,toolbar=0,width=590,resizable=0');
> 			Popup.focus();
> 			Popup.document.write('
> 			<TABLE>
> 			<xsl:copy-of select="tr"/>
> 			</TABLE>
> 			');
> 		</xsl:attribute>

The string-value of the contents of the xsl:attribute element are used for
the attribute value. The contents are:

- a text node containing the stuff leading up to <TABLE>
- a TABLE element node
- a text node contianing the whitespace after the </TABLE>

The string-value of an element is of course the concatenation of its
descendant text nodes, which in this case are going to be any text nodes
inside the 'tr' element being copied from the source tree.

You really want to, um, stringify the markup you intend to output. For the
<TABLE> and </TABLE> tags, this is easy:

Popup.document.write('
&lt;TABLE&gt;

&lt;/TABLE&gt;
');

Although it might be disconcerting to see this output in a similar fashion
in the HTML, it is, as was pointed out to me by James Clark in response to
an issue I raised re: 'script data'-type attributes in HTML, absolutely
correct and no Javascript-aware HTML user agent should have any problems
with it. You might be able to disable output escaping on the attribute
value, if your XSLT processor supports it. (SAXON does, and this might be
necessary because it's going to try to URLencode the entire href value).

The greater difficulty lies in converting the result tree fragment
generated by <xsl:copy-of select="tr"/> to a string. You will need to use
an extension function to do this, because you are working with node trees
in XSLT, not the original text from the source XML. Creating output in
XSLT is not done by pasting together arbitrary text strings containing
markup.

Sorry for the bad news.

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


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


Current Thread