I'd recommend the separate .js file route.  In fact, if you create a 
separate .js, you can have it load automatically by a simple edit of 
your Theme's sitemap.xmap file.   If you look in that file, you'll see 
"IncludePageMeta" sections like this:

<map:transform type="IncludePageMeta">
   <map:parameter name="stylesheet.screen#1" value="lib/style.css"/>
   <map:parameter name="stylesheet.screen#2" value="lib/style-ie.css"/>
</map:transform>

As you can see from the above, it's loading two CSS files for this 
theme.  You can do the same for Javascript files:

<map:transform type="IncludePageMeta">
   <map:parameter name="stylesheet.screen#1" value="lib/style.css"/>
   <map:parameter name="stylesheet.screen#2" value="lib/style-ie.css"/>
   <map:parameter name="javascript#1" value="lib/myscript.js"/>
   <map:parameter name="javascript#2" value="lib/anotherscript.js"/>
</map:transform>

In the above example, you are telling your Theme that your *.js files 
are in a "lib/" subdirectory in your Theme.  So, the path you give is 
always *relative* to the directory of your Theme.

[Side Note:]  If you look closely at the structural.xsl "buildHead" 
template, you'll see a section that says "<!--Add javascript-->" below 
the hardcoded javascript code.  This section is actually looping through 
all the javascript files that are being loaded by the call to 
"IncludePageMeta" in your sitemap.xmap.  This means that if you place 
them in the sitemap.xmap (as I noted above), you will NOT need to modify 
the structural.xsl.

The advantage to loading these in your sitemap.xmap is that it allows 
you to load *different* javascript files for *different* web browsers. 
So, you could potentially load different javascript code for I.E. than 
you load for Firefox, etc.

- Tim

Walker, David wrote:
> You could just write the Javascript in a seperate .js file and import it into 
> the HTML using a <script> tag.  That would free you from the constraints of 
> XSLT, and makes things cleaner anway.
> 
> --Dave
> ==================
> David Walker
> Library Web Services Manager
> California State University
> http://xerxes.calstate.edu
> ________________________________________
> From: mikan.d.dspace listmail [[email protected]]
> Sent: Wednesday, February 04, 2009 6:46 AM
> To: Andreas Geyrecker
> Cc: [email protected].
> Subject: Re: [Dspace-tech] Custom Javascript in Structural.xsl
> 
> Thanks Adnreas,
> 
> This seems to fix the problem with '&' signs etc. But now Im getting
> the following Javascript errors.
> This is strange since the same piece of code works fine in dummy HTML
> page. Something seems to go wrong when adding JS to XSL. What am I
> missing here?
> 
> "missing ) after for-loop control
> for (var i=0; i&lt;feed.value.items.length; i++) {\n"
> 
> "getFeed() function not found"
> 
> Mika
> 
> 
> 
> 2009/2/4 Andreas Geyrecker <[email protected]>:
>> Mika,
>>
>> try using a <![CDATA[ ... ]]> section for your javascript code.
>>
>> see also http://www.dpawson.co.uk/xsl/sect4/N9745.html
>>
>> Andi
>>
>>
>> 2009/2/4 mikan.d.dspace listmail <[email protected]>
>>> Im trying to add some custom Javscript code for our DSpace 1.5
>>> instances. The problem is though, that when compiling the source I get
>>> SAX errors because of '&' signs on Javascript code. Should I encode
>>> the code somehow or how could I get around this?
>>>
>>> The line that causes the problem is the following:
>>>
>>> var addr = 'http://my.site.org/run?&_render=json&_callback=trythis';
>>>
>>> org.xml.sax.SAXParseException: The reference to entity "_render" must
>>> end with the ';' delimiter.
>>>
>>> context:/file:/usr/local/jetty/jetty-6.1.12rc1/webapps/dikk/themes/TDS/./../dri2xhtml/structural.xsl
>>> - 226:98
>>>
>>> Cocoon stacktrace [hide]
>>> The reference to entity "_render" must end with the ';' delimiter.
>>>
>>> context:/file:/usr/local/jetty/jetty-6.1.12rc1/webapps/dikk/themes/TDS/./../dri2xhtml/structural.xsl
>>> - 226:98
>>>
>>> Thanks for any tips,
>>> Mika
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Create and Deploy Rich Internet Apps outside the browser with
>>> Adobe(R)AIR(TM)
>>> software. With Adobe AIR, Ajax developers can use existing skills and code
>>> to
>>> build responsive, highly engaging applications that combine the power of
>>> local
>>> resources and data with the reach of the web. Download the Adobe AIR SDK
>>> and
>>> Ajax docs to start building applications
>>> today-http://p.sf.net/sfu/adobe-com
>>> _______________________________________________
>>> DSpace-tech mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/dspace-tech
>>
> 
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> _______________________________________________
> DSpace-tech mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/dspace-tech
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> _______________________________________________
> DSpace-tech mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/dspace-tech
> 

-- 
Tim Donohue
Research Programmer, IDEALS
http://www.ideals.uiuc.edu/
University of Illinois
[email protected] | (217) 333-4648

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech

Reply via email to