Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XSLT with javascript ... grrrr!!

  • 15-12-2006 02:53PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 684 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 27,516 ✭✭✭✭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