Copied to clipboard

Flag this post as spam?

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


  • David 39 posts 119 karma points
    Mar 01, 2013 @ 14:25
    David
    0

    JavaScript with XSLT

    Hello,

    I hope someone can help me, I'm new to XSLT and I'm trying to extend XSLT with javascript to change  link text  within on a link within the navigation depending on the subdomain (es.domainname.co.uk or de.domain.co.uk etc.)

    I suspect it might be something to do with the namespace not being delaclared correctly?

    Thank you for any help on this.

    Regards

    David

    Please find below XSLT with the errors below that.


    <?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: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"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">

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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

      <script type="javascipt"> <![CDATA[
       var home = "";
        var url = location.href;
        code = url.substring(7,9);

        switch (code)
        {
            case "es":
                home = "Inicio";
                break;

            case "de":
                home = "";
                break;

            case "nl":
                home = "";
                break;

            default:
                home = "Home";
        }
        return home;]]>
      

      </script>
    <!-- The fun starts here -->
    <ul>
        <li><a href="/">Home</a></li>
    <xsl:apply-templates select="$currentPage/ancestor-or-self::* [@level=1]/*[@isDoc and string (umbracoNaviHide) != '1']"/>
     
    </ul>

    </xsl:template>
       
        <xsl:template match="*">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
           
            <xsl:if test="./*[@isDoc and string(umbracoNaviHide) != '1']">
              <ul>
              
                  <xsl:apply-templates select="./*[@isDoc and string (umbracoNaviHide) != '1']"/>
               
              </ul>
            </xsl:if>
          </li>
        </xsl:template>

    </xsl:stylesheet>


    Error occured

    System.Xml.Xsl.XslTransformException: Cannot find a script or an extension object associated with namespace 'urn:my-script '.
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    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)

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 06, 2013 @ 11:37
    Jan Skovgaard
    100

    Hi David

    If I understand what it is you're trying to do above then I suggest you use dictionary items instead.

    Since you probably have setup the hostnames with their corresponding culture in Umbraco you can simply create a dictionary item called "Home" where you write the correct words for each language.

    Then in your code, where it just says "Home" right now you simply write <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" /> and then Umbraco takes care of displaying the correct text.

    If you're going to use a lot of text-replacing depending on the site culture I suggest you read through this nice article by Chriztian Steinmeier http://pimpmyxslt.com/articles/dictionary-items/

    Hope this helps.

    /Jan

     

  • David 39 posts 119 karma points
    Mar 06, 2013 @ 12:37
    David
    0

    Jan,

    Thanks, I'll have a look into directory items instead tonight, and keep you posted.

    Sometimes I can get so involved in trying to resolve a problem in a certain way, it can be useful for someone else to suggest to appoach the problem from a different direction.

    Thank you very much.

    Regards

    David

  • David 39 posts 119 karma points
    Mar 07, 2013 @ 11:23
    David
    0

    Jan,

    I created a Dictionary item named 'Home' and added <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')" /> to the XSLT as you suggested and it worked.

    Thank you.

    Regards

    David

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 07, 2013 @ 12:09
    Jan Skovgaard
    0

    Hi David

    I'm very happy to hear that - and yes sometimes it's hard to see other options when one has chosen a certain direction. Glad you asked for some help so we could get you in the right direction :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft