Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XSLT with javascript ... grrrr!!

Options
  • 15-12-2006 2:53pm
    #1
    Registered Users Posts: 1,127 ✭✭✭


    I have this XSLT driven javascript linked list
                    <script language="javascript">
                        <xsl:comment>
                            function populateMenu() {
                                var priceplan = document.getElementById('priceplan').options[document.getElementById('priceplan').selectedIndex].value;
                                if(priceplan == 0) return;
                            <xsl:for-each select="priceplan">
                                if (priceplan == &quot;<xsl:value-of select="@ppshortname"/>&quot;) {
                                    var countries = new Array;
                                    <xsl:for-each select="./country">
    countries[countries.length] = new Option(&quot;<xsl:value-of select="@countryname"/>&quot;,&quot;<xsl:value-of select="@iso31661"/>&quot;);
                                    </xsl:for-each>
                                }
                            </xsl:for-each>
                                for(i=document.getElementById('country').options.length; i&gt;0; i--) { 
                                    document.getElementById('country').options[i] = null;
                                }                            
    
                                for(i=0; i&lt;countries.length; i++) {
                                    document.getElementById('country').options[i] = countries[i];
                                }
                            
                                document.getElementById('priceplan').options[0].selected = true;
                            }
                        </xsl:comment>
                    </script>
    

    ..but when I transform this and attempt to run, the following javascript error kicks in..
    Error: missing ) after for-loop control
    Source File: file:///E:/XMLGenerator/web/international/dropdown.html
    Line: 179, Column: 91
    Source Code:
                                for(i=document.getElementById('country').options.length; i&gt;0; i- -) { 
    

    Any ideas? There's an extra space being put in between the minus' in the decrement.

    Thanks


Comments

  • Registered Users Posts: 683 ✭✭✭Gosh


    I think you need to change
    for(i=document.getElementById('country').options.length; i&gt;0; i--) {
    

    to
    for(i=document.getElementById('country').options.length; i>0; i--) {
    

    and
    for(i=0; i&lt;countries.length; i++) {
    

    to
    for(i=0; i<countries.length; i++) {
    


    occurrences of " instead of the quote character will also cause a problem


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    ????

    if you are using <xsl:comment> you have to use HTML entities? You can only use those chars when you encapsulate it with CDATA directives (which is not an option because of the nested xsl directives in the javascript).

    anyone?


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    ????

    if you are using <xsl:comment> you have to use HTML entities? You can only use those chars when you encapsulate it with CDATA directives (which is not an option because of the nested xsl directives in the javascript).

    anyone?
    yep
    though you can use CDATA and intersperse xsl directives
    <CDATA blah my javascript/><xsl stuff><continuing DATA>


Advertisement