[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Javascript inside XSL(Just when I think I understand)


Subject: Re: [xsl] Javascript inside XSL(Just when I think I understand)
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Thu, 31 Jan 2002 19:02:21 -0800

Putting <![CDATA[ <!-- stuff --> ]]> in your stylesheet will not normally 
output the comment, it will output &lt;!-- stuff --&gt;.  It only works in 
this case because no output-escaping is performed when inside the <script> 
tag in HTML mode.

The more general way to do it is to put all your code in an <xsl:comment> tag.

On Wednesday 30 January 2002 13:22, Thomas B. Passin wrote:
> [Gene LaCava]
>
> > I have added some javascript inside my XSL file because I'm doing some
>
> pull
>
> > down menus.  As soon as I added the script I got the following error
>
> message
>
> > Error loading XSL Document :
> > ----------------------------
> > Error Code : -1072896766
> > Reason : A string literal was expected, but no opening quote character
> > was found.
>
> The code you included below runs without error (when you supply the missing
> closing tags, of course).  So the problem is probably in the xml document
> pulled in by the document() call in the variable.  You need to check that
> it is well-formed.
>
> However, once that is fixed, you will still not get what you want.  That is
> because your script is enclosed in a comment.  Comments will not be echoed
> to the output, so you won't get the script between the <script> </script>
> tags.
>
> The easiest solution is to put the entire chunk of javascript into a CDATA
> section, like this:
>
> ============================================
> <HTML>
> <![CDATA[
> <!--
> var aname='pull';
> var NS4 = (document.layers) ? 1 : 0;
> var IE = (document.all) ? 1 : 0;
> var DOM = (parseInt(navigator.appVersion) >=5) ? 1 : 0;
> var MAC = ((navigator.appVersion.indexOf("PPC") >0) ||
> (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
>
> //global nav
>  function ShowLayer(){return};
>  function OutLayer(){return};
> if (document.layers) {
>   appVer = navigator.appVersion.substring(0,4);
>   if (appVer < 4.06) NS4 = 0;
> }
> if (NS4 || IE || DOM) globalPulldown = 1;
> if (!globalPulldown) event = null;
> //-->]]>
>
> </xsl:template>
>
> =================================================
>
> This  gives your desired output.
>
> As an aside, your script should go into an explicit head element, rather
> that beoing plunked down directly inside the <HTML> element.  it's true
> that the start and end tags of the head element are optional, but it's
> better practice and will help prevent mistakes if you go to xhtml.
>
> Cheers,
>
> Tom P
>
> > I know the XSL File and Jscript work because they work perfectly in test
> > programs Ive writtent, now I'm trying to bring them together.  Anyone
> > have any ideas ?
> >
> > Thank You
> > <?xml version="1.0"  ?>
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > <xsl:output method="html" />
> > <xsl:variable name="hours" select="document('DeptHours.xml')"/>
> > <xsl:param name="id"/>
> > <xsl:template match="dataroot">
> >
> >
> > <HTML>
> > <script language="JavaScript1.2">
> > <!--
> > var aname='pull';
> > var NS4 = (document.layers) ? 1 : 0;
> > var IE = (document.all) ? 1 : 0;
> > var DOM = (parseInt(navigator.appVersion) >=5) ? 1 : 0;
> > var MAC = ((navigator.appVersion.indexOf("PPC") >0) ||
> > (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
> >
> > //global nav
> >  function ShowLayer(){return};
> >  function OutLayer(){return};
> > if (document.layers) {
> >   appVer = navigator.appVersion.substring(0,4);
> >   if (appVer < 4.06) NS4 = 0;
> > }
> > if (NS4 || IE || DOM) globalPulldown = 1;
> > if (!globalPulldown) event = null;
> > //-->
> > </script>
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
Peter Davis
If Bill Gates is the Devil then Linus Torvalds must be the Messiah.
	-- Unknown source

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



Current Thread
Keywords