Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS function call as XSL output?

    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:
    Code:
    <?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>
     </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:choose>
       <xsl:when test="not(element-available('speed')) or @speed = 'normal'">
        <xsl:text>30</xsl:text>
       </xsl:when>
       <xsl:when test="@speed = 'fastest'">
        <xsl:text>20</xsl:text>
       </xsl:when>
       <xsl:when test="@speed = 'fast'">
        <xsl:text>25</xsl:text>
       </xsl:when>
       <xsl:when test="@speed = 'slow'">
        <xsl:text>35</xsl:text>
       </xsl:when>
       <xsl:when test="@speed = 'slowest'">
        <xsl:text>40</xsl:text>
       </xsl:when>
      </xsl:choose>
     <xsl:apply-templates select="text" mode="scroll"/>
     <xsl:text>);</xsl:text>
     </script>
    </xsl:template>
    <xsl:template match="text" mode="scroll">
     <xsl:text>,"</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>
    </xsl:template>
    </xsl:stylesheet>
    Thanks a lot for your help.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

    patrick

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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().


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •