Re: [xsl] javascript, xsl and xml

Subject: Re: [xsl] javascript, xsl and xml
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 6 Aug 2004 11:52:14 +0100
  I have a child window and am looking to pass some of the xml within it
  to it's parent. 
  The problem is: any '<' '>' or '"' contained within the xml (as there
  will be) causes the javascript function call to fail.

  Is there anyway in a stylesheet to pass xml into a function without the
  contents of the xml causing problems? Do I need to convert every < to
  &lt; < to &gt; etc - if so is there a quick way to do this?

you wern't very specifc where your problem was, if

ypu mean that you have in the xml source unquoted < then the input is
not well formed (ie, not XML) so will be a fatal error to any XML
application, not just XSLT.

You can use &lt; or equivalently put a CDATA section around teh whole
block as in
<foo><![CDATA[
 1 < 2 < 3
]]></foo>

To XSLT that is identical input to



<foo>
 1 &lt; 2 7gt; 3
</foo>

That's all about the input, but as you said "javascript function call to
fail". perhaps your problem is in the output.

If you have some input quoted as above and copy it to a script block
in the output it will come out as

<script>
  1 &lt; 2 &gt; 3
</script>

if you are using the xml output method or

<script>
 1 < 2 < 3
</script>

if you are using the html output method which is teh default if the top
level output element is html in no-namespace.

Quoting < and & in script elements is teh correct thing to do in XHTML
but if you send the file to a browser that doesn't know anything about
xhtml (like for instance IE) then it will trip over the quoting as
&lt; does not mean < in an html script element as & is not markup there
so it literally means the four characters & l t ;.

If you specify cdata-section-elements="script" in your stylesheet the
element will probably be output as

<script><![CDATA[
 1 < 2 < 3
]]></script>
which is equivalent as XHTML, as HTML it sould just be a syntax error as
< is not special inside an html <script>  so <![CDATA[ should not start
 a CDATA section, but you will probably find it works, although I think
 best is to generate html using the html output method rather than rely
 on spurious html browser parsing of xhtml files.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread