Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Bielefeldt 11 posts 31 karma points
    Mar 16, 2011 @ 16:42
    James Bielefeldt
    0

    Javascript in XSLT namespace error

    Here is my XSLT...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
     xmlns:myjs="myjs"
     xmlns:umbraco.library="urn:umbraco.library"
     xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
     xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:pdcalendar="urn:pdcalendar" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
     exclude-result-prefixes="msxsl myjs msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary pdcalendar PS.XSLTsearch ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <msxsl:script language="JavaScript" implements-prefix="myjs">
    <![CDATA[
    function jumpToPage(){
    // stuff goes here
    }
    ]]>
    </msxsl:script>

    <!-- The fun starts here -->
    <select>
     <xsl:attribute name="onChange">
     <xsl:value-of select="myjs:jumpToPage(this.selectedValue)"/>
    </xsl:attribute>

    <xsl:for-each select="$currentPage/*">
     <option>
     <xsl:attribute name="value">
     <xsl:value-of select="@urlName"/>
    </xsl:attribute>
    <xsl:value-of select="@nodeName"/>
    </option>
    </xsl:for-each>
    </select>

    </xsl:template>

    </xsl:stylesheet>

     

    I get this error:

    System.Xml.Xsl.XslTransformException: Cannot find a script or an extension object associated with namespace 'myjs'.
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    What am I missing?

     

    Thanks in advance!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 16, 2011 @ 17:02
    Chriztian Steinmeier
    0

    Hi James,

    This is JavaScript you want to be able to execute in the browser (client-side), right?

    The <msxsl:script> element is used for scripting stuff the XSLT can't do very well (like Regular Expression, Date calculations etc.).

    You can just do something like this:

    <script type="text/javascript"> 
    <![CDATA[
    function jumpToPage() {
        // stuff goes here
    }
    ]]>
    </script>
    ...
    <select onchange="jumpToPage(this.selectedValue)">
        <xsl:for-each select="$currentPage/*">
            <option value="{@urlName}">
                <xsl:value-of select="@nodeName" />
            </option>  
        </xsl:for-each>
    </select> 

    /Chriztian

  • James Bielefeldt 11 posts 31 karma points
    Mar 16, 2011 @ 17:25
    James Bielefeldt
    0

    Man, was I making that way too difficult. Many thanks!

Please Sign in or register to post replies

Write your reply to:

Draft