CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2001
    Location
    Michigan
    Posts
    41

    Javascript in a XSLT

    I am having a problem putting a javascript function in a XSLT.
    Here is my XSLT, I simplified it for this example:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:totalSys="TotalSystem"
    extension-element-prefixes="totalSys">
    <xslutput method="html" encoding="utf-8" indent="yes"/>

    <lxslt:component prefix="totalSys" functions="toggle">
    <lxslt:script lang="javascript">

    function toggle() {
    alert("hi");
    }

    </lxslt:script>
    </lxslt:component>

    <html>
    <head>
    <title>"Errors"</title>
    </head>
    <body>
    <a href="#" onclick="totalSys:toggle()">
    <xsl:text>hi</xsl:text>
    </a>
    </body>
    </html>

    When my sheet is generated, I click on my link and I get an error from my browser it says that an Object is expected.
    What am I doing wrong?
    Thanks in advance

  2. #2
    Join Date
    Aug 2001
    Location
    Russia, Moscow
    Posts
    26
    Hi
    You misused the semantic of this feature.
    This feature concerns the usage of JS on the stage of transformation. (For sample in the XSLT expression)

    In your case it is just html script.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" encoding="utf-8" indent="yes"/>
      <xsl:template match="/">
        <html>
          <head>
            <title>"Errors"</title>
          </head>
          <script>
    function toggle() {
    alert("hi");
    } 
        </script>
          <body>
            <a href="#" onclick="toggle()">
              <xsl:text>hi</xsl:text>
            </a>
          </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>
    Denis.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured