SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I this javascript in XSL?

    Hello,
    I'm not that good in Javascript and I'm new in XSLT,
    but the project I'm starting to join is using XSLT, and I need to add java script in that.

    First I had Calendar javascript before, and I need to put that calendar thingy
    inside the .xsl file

    Here is the html file that used calendar

    Code:
    <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title> New Post </title>
      <meta http-equiv="Content-Type"
        content="text/html; charset=iso-8859-1 "/>
        <script type="text/javascript" src="calendarDateInput.js">
    /***********************************************
    * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
    * Script featured on and available at http://www.dynamicdrive.com
    * Keep this notice intact for use.
    ***********************************************/
    </script>
    </head>
    <body>
    ....
    <label>On Date : </label>
    <script>DateInput('onDate', true, 'YYYY-MM-DD', '<?=shownDate($onDate);?>')</script>
    ...
    </body>
    </html>
    And here is the xsl file I need to add java script

    Code:
    	<xsl:template match="node()" mode="head">
    	<head>
            <script type="text/javascript">
            <xsl:attribute name="src"><xsl:text>calendarDateInput.js</xsl:text></xsl:attribute>
            <xsl:comment>Comment added so script is recognised</xsl:comment>
            </script>
    
    	</head>
    	</xsl:template>
    Then

    Code:
    <xsl:template name="report-params-dates">
    		<!-- Start Date  We use calendar widget -->
    		<label for="start" id="start_label">			
    			<xsl:text>Start Date: </xsl:text>
                <script>DateInput('onDate', true, 'YYYY-MM-DD', '<?=shownDate($onDate);?>')</script>
                 
    		</label>
    </xsl:template>
    The result? There is nothing shown. I know I didn't do correctly in the head part - maybe this part is good?
    as well as <xsl:template name="report-params-dates"> part, but I don't know how to fix it.

    I really appreciate your help.

    Thanks,

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the wonderful world of javascript with xsl....
    First question, do you send XML+XSL to the browser, and let it do the transformation, or do you transform it on the server and send HTML to the browser ?

    If you answer the first, I'm sorry for you, but you cannot use that script.
    In XML+XSL mode, the javascript have to use DOM functions only. No innerHTML, no document.write, only pure document.createElement() and element.appendChild()...
    This lead to a vast majority of javascript already done utilites to miserably fail.
    I particulary think of wysiwyg html editor here...

    Second, you might need to envelop your script into CDATAS section, to indicate the XSL parser that the { and } and entities in the javascript section are not to be parsed.
    It would cause the transformation to fail otherwise on those characters.
    Like this:
    Code:
    <![CDATA[<sender>John Smith</sender>]]>

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh,
    I must have been out of my mind.
    Actually the problem was I was testing on a server, and I didn't upload
    the .js file on the server thinking I was testing on my local.

    Anyway, thanks for your reply.


Bookmarks

Posting Permissions

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