How to use JavaScript array in xsl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rupak
    New Member
    • Jan 2008
    • 25

    How to use JavaScript array in xsl

    I want to use a array created in javascript whoes value is drived from a xml file by DOM.

    now i want to use that array to creat the google chart by calling that array value in the imge source path.

    Code:
    var valueArray = new Array();
    var myId = document.getElementById("GraphThisTable");
    var rows = myId.getElementsByTagName("tr");
    for(i = 1; i != rows.length; i++)
    {
    var cols = rows[i].getElementsByTagName("td");
    valueArray[i - 1] = cols[1].innerHTML;
    }
    alert(valueArray);
    now want to use the "valueArray " in xsl to set image attribute
    ex:

    Code:
    <img><xsl:attribute name="src">http://chart.apis.google.com/chart?cht=p3&amp;chd=t:1,1,1,3,1,2,2,2&amp;chs=250x100&amp;chl=2001|2003|2004|2000|2002|3001|3002|3003</xsl:attribute></img>
    Thus insted of "chd=t:1,1,1,3, 1,2,2,2" i want to use "chd=t:$valueArray"

    Can any one help me out how to write the xsl for the same using javascript variable in xsl
    Last edited by acoder; Dec 11 '08, 10:27 AM. Reason: changed quote to code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you want to pass a simple type value (like string or number) to xsl, you can use parameters (<xsl:param>) for that, but I'm not aware that complex types (like arrays or objects) can be passed. see Setting Parameters – MDC.

    on the other hand, what is the xml file your xslt is applied to? if there is currently none you may condider transforming your array into xml and let the xslt work on that, you don't even need parameters then. or if there is already one, import the transformed array via the document() function in xslt.

    regards

    PS: ask a mod to move this thread to the answers section

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      rupak, you posted this in the insights section rather than the answers forum section. I've moved it across for you.

      Also, remember to use code tags when posting code, not quote tags. Thanks.

      Moderator.

      Comment

      Working...