View Full Version : JS function call as XSL output?

01-24-2003, 11:20 PM
Hello, I am working with an xsl file that I want to create a scroller, but the scroller is not completely self contained and it needs to call a javascript function called addScroller() in order to start working. Is there a way that I can do this? This is what I have written right now:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="scroller">
<div id="spacer{generate-id()}" style="height: {@height}px; width: {@width}px;"></div>
<div id="clipper{generate-id()}" style="position: absolute; top: 0px; width: 0px; height: 0px; width: 0px;">
<div id="scroller{generate-id()}" style="position: absolute; top: 0px; width: 0px; height: 0px; width: 0px;"></div>
<script type="text/javascript">
<xsl:text>addScroller(getElement('spacer</xsl:text><xsl:value-of select="generate-id()"/><xsl:text>'), getElement('clipper</xsl:text><xsl:value-of select="generate-id()"/><xsl:text>'), getElement('scroller</xsl:text><xsl:value-of select="generate-id()"/><xsl:text>'), </xsl:text>
<xsl:when test="not(element-available('speed')) or @speed = 'normal'">
<xsl:when test="@speed = 'fastest'">
<xsl:when test="@speed = 'fast'">
<xsl:when test="@speed = 'slow'">
<xsl:when test="@speed = 'slowest'">
<xsl:apply-templates select="text" mode="scroll"/>
<xsl:template match="text" mode="scroll">
<xsl:text>,"</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>

Thanks a lot for your help.

01-25-2003, 08:07 PM
Can you not just generate a <script type="text/javascript" href="somefile.js"></script> line in your page and let that do the business for you?


01-25-2003, 08:46 PM
I haven't run through your code specifically, but the general approach seems okay - I've done similair things - using XSL to generate a set of js arrays.

You might find that if you set the <xsl:output/> to text, it's easier to work with. But otherwise - what's actually the problem?

01-25-2003, 09:35 PM
I can't just include another js file, I already do to get the function addScroller(), because the call has to be specific to the generate-id().