title: Calling a user defined function written in javascript using xsl
body: <p>I have a javascript inside the XSL style sheet. In the javascript, i have a function, getName(node).
  How do i call this in my xsl?
  I had used xsl:eval=getname(this) earlier. It worked till IE8. Hasnt worked from IE9 onwards. 
  Can i use xsl:value-of-select? or any other tips to make it work ?
  Thank you in advance.</p>
  
  <pre><code>    &lt;xsl:script language='JavaScript'&gt;&lt;![CDATA[
  
      var sSobeysRegion = "Sobeys West";
      var sReceiverID = "SOBEYSCANADA:ZZ";
      var ATLANTIC = "Sobeys Atlantic";
      var WEST = "Sobeys West";
      var QUEBEC = "Sobeys Quebec";
      var ONTARIO = "Sobeys Ontario";
      var option1 = ATLANTIC ;
      var option2 = WEST ;
      var option3 = QUEBEC ;
      var option4 = ONTARIO ;
  
      function getRegion(sVar)
      {
          if (sVar == sSobeysRegion) {
              return true;
          }
          else {
              return false;
          }
      }
  
      function setReceiverID(sTmp)
      {
          if (sTmp == "Sobeys Atlantic") {
              sReceiverID = "SOBNBTATLTST:ZZ";
              option1 = ATLANTIC;
              option2 = WEST;
              option3 = ONTARIO;
              option4 = QUEBEC;
          }
          else if (sTmp == "Sobeys West") {
              sReceiverID = "SOBNBTWSTTST:ZZ";
              option2 = ATLANTIC;
              option1 = WEST;
              option3 = QUEBEC;
              option4 = ONTARIO;
          }
          else if (sTmp == "Sobeys Quebec") {
              sReceiverID = "SOBNBTQUETST:ZZ";
              option2 = ATLANTIC;
              option3 = WEST;
              option4 = ONTARIO;
              option1 = QUEBEC;
          }
          else if (sTmp == "Sobeys Ontario") {
              sReceiverID = "SOBNBTONTTST:ZZ";
              option2 = ATLANTIC;
              option3 = WEST;
              option1 = ONTARIO;
              option4 = QUEBEC;
          }
      }
      function getRegionValue(Node)
      {
          var sRegion = "TESTID";
          var xmldoc = Node.ownerDocument;
          var root = xmldoc.documentElement;
  
          sRegion = root.getAttribute("Region");
  
          sSobeysRegion = sRegion;
          setReceiverID(sSobeysRegion)
  
  //      return sRegion;
          return "";
      }
      var iLineItemCount = 0;
  
      function addLineItemCount()
      {
          ++iLineItemCount;
  
          return iLineItemCount;
      }
      function getLineItemCount()
      {
          return iLineItemCount;
      }
  
      function getEditNodeName(Node)
      {
          var sTmp = "";
  //      var xmldoc = Node.ownerDocument;
  //      var root = xmldoc.documentElement;
  //      var attribute = null;
  
  //      sTmp = Node.nodeName;
  
  //      attribute = xmldoc .createAttribute("EditItemCount");
  //      Node.setAttributeNode(attribute);
  //      Node.setAttribute("EditItemCount", getEditItemCount());
  
          //attribute = Node.getAttributeNode();
  //      sTmp += ", " + Node.getAttribute("EditItemCount");
  //      sTmp += ", document.form." + Node.nodeName + Node.getAttribute("EditItemCount") + ".value";
  //      sTmp = "this";
  
          sTmp = "this, " + getIndex(Node);
  
          return sTmp;
      }
      function getName(Node)
      {
          var sTmp = "";
  
          sTmp =  Node.nodeName;
  
          return sTmp;
      }
  
      function getValue(Node)
      {
          var sTmp = "";
  
          if (Node.childnodes(0)!= null) {
              sTmp = Node.childnodes(0).nodeValue;
          }
          return sTmp;
      }
      function setValue(Node, sValue)
      {
  
  
      }
      function TransformDate(Node)
      {
          var sTmp = 0;
          var sDate = "";
  
          sTmp = Node.childnodes(0).nodeValue;
  
          sDate = sTmp.substring(4,6) + "/" + sTmp.substring(6,8) + "/" + sTmp.substring(0,4);
  
          return sDate;
      }
      var iLineCount = 0;
      function getLineCount(Node)
      {
          ++iLineCount;
  
          return iLineCount;
      }
      var iEditItemCount = 0;
  
      function getEditItemCount(Node)
      {
          ++iEditItemCount;
  
          return iEditItemCount;
      }
                  function getIndex(node)
                  {
                      var iCount = 0;
                      var previousNode = null;
  
                      while(node.parentNode != null){
                          previousNode =  node.previousSibling;
                          while(previousNode != null){
                              if ((previousNode.nodeName != "#document") &amp;&amp; (previousNode.nodeName != "xml")
                              &amp;&amp; (previousNode.nodeName != "xml-stylesheet")) {
                                  iCount += countChildren(previousNode);
  //                                  sValue += previousNode.nodeName + "%";
                                      ++iCount;
                              }
                              previousNode =  previousNode.previousSibling;
                          }
  
                          node = node.parentNode;
                          if (node.nodeName != "#document") {
                              ++iCount;
  //                          sValue += node.nodeName + "*"
                          }
                      }
                      return(iCount);
                  }
                  function countChildren(node)
                  {
                      var iCount = 0;
                      var iTotal = 0;
                      var intNode = 0;
  
                      iCount = node.childNodes.length;
  
                      if (iCount &gt; 0) {
                          for (intNode = 0; intNode &lt; iCount; intNode++) {
                            if (node.childNodes(intNode).nodeName != "#text") {
                                iTotal += countChildren(node.childNodes(intNode));
  //                             sValue += node.childNodes(intNode).nodeName + "&amp;";
                                 ++iTotal;
  
                            }
                          }
                      }
                      return(iTotal);
                  }
                  function showNext()
                  {
                  }
  
  ]]&gt;&lt;/xsl:script&gt;
  </code></pre>
  
  <p>This is the javascript present in the xsl:script block.
  The call to this function is below.</p>
  
  <pre><code>`enter code here`
  
  
      &lt;xsl:template match="SAC_SAC_01_248"&gt;
  &lt;xsl:element name='select'&gt;
      &lt;xsl:attribute name='class'&gt;select&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name='name'&gt;&lt;xsl:value-of-select = "getName(this)"&gt;/&gt;&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name='defaultvalue'&gt;&lt;xsl:value-of-select = "getValue(this)"/&gt;&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name='style'&gt;color: black; font-size: 10px;font-weight: normal;font-family: Verdana, Arial, Helvetica, sans-serif&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name='onchange'&gt;onNewCodeChange(&lt;xsl:value-of-select = "getEditNodeName(this)"/&gt;, 2)&lt;/xsl:attribute&gt;
      &lt;xsl:element name='Option'&gt;
                  &lt;xsl:attribute name='value'&gt;&lt;/xsl:attribute&gt;
      &lt;/xsl:element&gt;
      &lt;xsl:element name='Option'&gt;
                  &lt;xsl:attribute name='value'&gt;A&lt;/xsl:attribute&gt;
                  A
      &lt;/xsl:element&gt;
      &lt;xsl:element name='Option'&gt;
                  &lt;xsl:attribute name='value'&gt;C&lt;/xsl:attribute&gt;
                  C
      &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>