Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击按钮时如何调用此函数?(Javascript、XSLT、XML、HTML)_Javascript_Html_Xml_Xslt - Fatal编程技术网

单击按钮时如何调用此函数?(Javascript、XSLT、XML、HTML)

单击按钮时如何调用此函数?(Javascript、XSLT、XML、HTML),javascript,html,xml,xslt,Javascript,Html,Xml,Xslt,我正试图在XML/XSL类中为一个学校项目开发一个页面,该页面使用按钮调用一个函数,该函数显示一个国家的信息。我可以通过下拉列表得到类似的结果,但当我尝试将其更改为按钮时,出现了一些问题,我无法确定是什么 xsl: <?xml version='1.0' encoding='UTF-8' ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> &l

我正试图在XML/XSL类中为一个学校项目开发一个页面,该页面使用按钮调用一个函数,该函数显示一个国家的信息。我可以通过下拉列表得到类似的结果,但当我尝试将其更改为按钮时,出现了一些问题,我无法确定是什么

xsl:

<?xml version='1.0' encoding='UTF-8' ?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <style>
                    #select {
                         position: absolute;
                         left: 0;
                         top: 0;
                         background-color: black;
                         width: 20%;
                         height: 100%
                     }

                     h1 {
                         color: white;
                         text-align: center;
                     }

                     h2 {
                         color: white;
                     }

                     a {
                         color: white;
                     }

                     #demo {
                         position: absolute;
                         left: 20%;
                         top: 0;
                         width: 80%;
                         height: 100%;
                     }

                     button {
                         background-color: Transparent;
                         background-repeat: no-repeat;
                         border: none;
                         color: white;
                     }
                </style>
            </head>
            <body>
                <div id="select">
                    <h2>Select your country:</h2>
                    <xsl:for-each select="countries/country">
                        <button style="display: block;" id="mySelect" onclick="myFunction()">
                            <xsl:value-of select="name"/>
                            <xsl:attribute name="value">
                                <![CDATA[ <h1 style="color:#]]>
                                <xsl:value-of select="color"/>
                                <![CDATA[ "> ]]>
                                <xsl:value-of select="name"/>
                                <![CDATA[ </h1> ]]>
                                <![CDATA[ <p>]]>
                                <xsl:value-of select="name"/> has a population of 

                                <xsl:value-of select="format-number(population,'#,000')"/>. Their currency is called the 

                                <xsl:value-of select="currency"/> and their spoken language is 

                                <xsl:value-of select="official_language"/> Their capital is called 

                                <xsl:value-of select="capital"/>
                                <![CDATA[</p><p> ]]>
                                <xsl:value-of select="interesting_fact"/>
                                <![CDATA[ </p> ]]>
                            </xsl:attribute>
                        </button>
                    </xsl:for-each>
                </div>
                <div id="demo"/>
                <script>
        function myFunction() { var x = document.getElementById("mySelect").value; document.getElementById("demo").innerHTML = x; }
        </script>
            </body>
        </html>
    </xsl:template>undefined
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="final.xsl" ?>
<countries>
    <country>
        <name>Brazil</name>
        <population>208733102</population>
        <currency>Real</currency>
        <official_language>Portuguese</official_language>
        <capital>Brasilia</capital>
    <interesting_fact>Brazil's large territory comprises different ecosystems, such as the Amazon rainforest, recognized as having the greatest biological diversity in the world, with the Atlantic Forest and the Cerrado, sustaining the greatest biodiversity.[172] In the south, the Araucaria pine forest grows under temperate conditions. The rich wildlife of Brazil reflects the variety of natural habitats. Scientists estimate that the total number of plant and animal species in Brazil could approach four million, mostly invertebrates.</interesting_fact>
    <color>379e4d</color>
</country>
<country>
    <name>United Kingdom</name>
    <population>65648100</population>
    <currency>Pound sterling</currency>
    <official_language>English</official_language>
    <capital>London</capital>
    <interesting_fact>The UK has a parliamentary government based on the Westminster system that has been emulated around the world: a legacy of the British Empire. The parliament of the United Kingdom meets in the Palace of Westminster and has two houses: an elected House of Commons and an appointed House of Lords. All bills passed are given Royal Assent before becoming law.</interesting_fact>
    <color>d1361b</color>
</country>
<country>
    <name>United States of America</name>
    <population>325719178</population>
    <currency>Dollar</currency>
    <official_language>English</official_language>
    <capital>Washington D.C.</capital>
    <interesting_fact>The United States had the highest prison population rate in the world, at 716 per 100,000 people. More than half the 222 countries and territories in the World Prison Population List, by the U.K.-based International Center for Prison Studies, had rates below 150 per 100,000.</interesting_fact>
    <color>282a7f</color>
</country>
<country>
    <name>China</name>
    <population>1403500365</population>
    <currency>Yuan</currency>
    <official_language>Standard Chinese</official_language>
    <capital>Beijing</capital>
    <interesting_fact>Archaeological evidence suggests that early hominids inhabited China between 2.24 million and 250,000 years ago. The hominid fossils of Peking Man, a Homo erectus who used fire, were discovered in a cave at Zhoukoudian near Beijing; they have been dated to between 680,000 and 780,000 years ago. The fossilized teeth of Homo sapiens (dated to 125,000–80,000 years ago) have been discovered in Fuyan Cave in Dao County, Hunan. Chinese proto-writing existed in Jiahu around 7000 BCE, Damaidi around 6000 BCE, Dadiwan from 5800–5400 BCE, and Banpo dating from the 5th millennium BCE.</interesting_fact>
    <color>f92713</color>
</country>
</countries>

#挑选{
位置:绝对位置;
左:0;
排名:0;
背景色:黑色;
宽度:20%;
身高:100%
}
h1{
颜色:白色;
文本对齐:居中;
}
氢{
颜色:白色;
}
a{
颜色:白色;
}
#演示{
位置:绝对位置;
左:20%;
排名:0;
宽度:80%;
身高:100%;
}
钮扣{
背景色:透明;
背景重复:无重复;
边界:无;
颜色:白色;
}
选择您的国家/地区:
]]>
]]>
]]>
人口
. 他们的货币称为欧元
他们的口语是
他们的首都叫做
]]>
]]>
函数myFunction(){var x=document.getElementById(“mySelect”).value;document.getElementById(“demo”).innerHTML=x;}
未定义
xml:

<?xml version='1.0' encoding='UTF-8' ?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <style>
                    #select {
                         position: absolute;
                         left: 0;
                         top: 0;
                         background-color: black;
                         width: 20%;
                         height: 100%
                     }

                     h1 {
                         color: white;
                         text-align: center;
                     }

                     h2 {
                         color: white;
                     }

                     a {
                         color: white;
                     }

                     #demo {
                         position: absolute;
                         left: 20%;
                         top: 0;
                         width: 80%;
                         height: 100%;
                     }

                     button {
                         background-color: Transparent;
                         background-repeat: no-repeat;
                         border: none;
                         color: white;
                     }
                </style>
            </head>
            <body>
                <div id="select">
                    <h2>Select your country:</h2>
                    <xsl:for-each select="countries/country">
                        <button style="display: block;" id="mySelect" onclick="myFunction()">
                            <xsl:value-of select="name"/>
                            <xsl:attribute name="value">
                                <![CDATA[ <h1 style="color:#]]>
                                <xsl:value-of select="color"/>
                                <![CDATA[ "> ]]>
                                <xsl:value-of select="name"/>
                                <![CDATA[ </h1> ]]>
                                <![CDATA[ <p>]]>
                                <xsl:value-of select="name"/> has a population of 

                                <xsl:value-of select="format-number(population,'#,000')"/>. Their currency is called the 

                                <xsl:value-of select="currency"/> and their spoken language is 

                                <xsl:value-of select="official_language"/> Their capital is called 

                                <xsl:value-of select="capital"/>
                                <![CDATA[</p><p> ]]>
                                <xsl:value-of select="interesting_fact"/>
                                <![CDATA[ </p> ]]>
                            </xsl:attribute>
                        </button>
                    </xsl:for-each>
                </div>
                <div id="demo"/>
                <script>
        function myFunction() { var x = document.getElementById("mySelect").value; document.getElementById("demo").innerHTML = x; }
        </script>
            </body>
        </html>
    </xsl:template>undefined
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="final.xsl" ?>
<countries>
    <country>
        <name>Brazil</name>
        <population>208733102</population>
        <currency>Real</currency>
        <official_language>Portuguese</official_language>
        <capital>Brasilia</capital>
    <interesting_fact>Brazil's large territory comprises different ecosystems, such as the Amazon rainforest, recognized as having the greatest biological diversity in the world, with the Atlantic Forest and the Cerrado, sustaining the greatest biodiversity.[172] In the south, the Araucaria pine forest grows under temperate conditions. The rich wildlife of Brazil reflects the variety of natural habitats. Scientists estimate that the total number of plant and animal species in Brazil could approach four million, mostly invertebrates.</interesting_fact>
    <color>379e4d</color>
</country>
<country>
    <name>United Kingdom</name>
    <population>65648100</population>
    <currency>Pound sterling</currency>
    <official_language>English</official_language>
    <capital>London</capital>
    <interesting_fact>The UK has a parliamentary government based on the Westminster system that has been emulated around the world: a legacy of the British Empire. The parliament of the United Kingdom meets in the Palace of Westminster and has two houses: an elected House of Commons and an appointed House of Lords. All bills passed are given Royal Assent before becoming law.</interesting_fact>
    <color>d1361b</color>
</country>
<country>
    <name>United States of America</name>
    <population>325719178</population>
    <currency>Dollar</currency>
    <official_language>English</official_language>
    <capital>Washington D.C.</capital>
    <interesting_fact>The United States had the highest prison population rate in the world, at 716 per 100,000 people. More than half the 222 countries and territories in the World Prison Population List, by the U.K.-based International Center for Prison Studies, had rates below 150 per 100,000.</interesting_fact>
    <color>282a7f</color>
</country>
<country>
    <name>China</name>
    <population>1403500365</population>
    <currency>Yuan</currency>
    <official_language>Standard Chinese</official_language>
    <capital>Beijing</capital>
    <interesting_fact>Archaeological evidence suggests that early hominids inhabited China between 2.24 million and 250,000 years ago. The hominid fossils of Peking Man, a Homo erectus who used fire, were discovered in a cave at Zhoukoudian near Beijing; they have been dated to between 680,000 and 780,000 years ago. The fossilized teeth of Homo sapiens (dated to 125,000–80,000 years ago) have been discovered in Fuyan Cave in Dao County, Hunan. Chinese proto-writing existed in Jiahu around 7000 BCE, Damaidi around 6000 BCE, Dadiwan from 5800–5400 BCE, and Banpo dating from the 5th millennium BCE.</interesting_fact>
    <color>f92713</color>
</country>
</countries>

巴西
208733102
真实的
葡萄牙语
巴西利亚
巴西的大片领土由不同的生态系统组成,如亚马逊雨林,被认为是世界上生物多样性最丰富的地区,而大西洋森林和塞拉多森林则维持着最大的生物多样性。[172]在南部,南洋杉林生长在温带条件下。巴西丰富的野生动物反映了自然栖息地的多样性。科学家估计,巴西的动植物物种总数可能接近400万,其中大部分是无脊椎动物。
379e4d
大不列颠联合王国
65648100
英镑
英语
伦敦
英国有一个基于威斯敏斯特体系的议会政府,这个体系已经被全世界效仿:这是大英帝国的遗产。英国议会在威斯敏斯特宫举行会议,共有两院:民选下议院和任命的上议院。所有通过的法案在成为法律之前都得到了王室的批准。
d1361b
美利坚合众国
325719178
美元
英语
华盛顿哥伦比亚特区
美国有世界上最高的监狱人口比率,每10万人中有716人。总部位于英国的国际监狱研究中心的世界监狱人口排行榜中,超过222个国家和地区的半数以上,每100000人的比率低于150。
282a7f
中国
1403500365
元
标准中文
北京
考古学证据表明,224万至25万年前,早期人类曾在中国居住。北京猿人的原始人化石是在北京附近周口店的一个洞穴中发现的,这是一种使用火的直立人;它们可以追溯到68万到78万年前。湖南道县福岩洞发现了智人牙齿化石(距今125000-80000年)。中国的原始文字存在于公元前7000年左右的嘉湖、公元前6000年左右的大梅地、公元前5800-5400年的大地湾和公元前5千年的半坡。
f92713

非常感谢您的任何帮助

我做了一些更改,您可以在下面的代码更改中找到解决方案。

    <?xml version='1.0' encoding='UTF-8' ?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <style>
                    #select {
                         position: absolute;
                         left: 0;
                         top: 0;
                         background-color: black;
                         width: 20%;
                         height: 100%
                     }

                     h1 {
                         color: white;
                         text-align: center;
                     }

                     h2 {
                         color: white;
                     }

                     a {
                         color: white;
                     }

                     #demo {
                         position: absolute;
                         left: 20%;
                         top: 0;
                         width: 80%;
                         height: 100%;
                     }

                     button {
                         background-color: Transparent;
                         background-repeat: no-repeat;
                         border: none;
                         color: white;
                     }
                </style>
            </head>
            <body>
                <div id="select">
                    <h2>Select your country:</h2>
                    <xsl:for-each select="countries/country">
                        <button style="display: block;" id="mySelect" onclick="myFunction(this)">
                                <xsl:attribute name="name">
                                     <xsl:value-of select="name"/>
                                </xsl:attribute>
                                <xsl:attribute name="value">
                                 <xsl:value-of select="name"/>
                                <![CDATA[ <h1 style="color:]]>
                                <xsl:value-of select="color"/>
                                <![CDATA[ "> ]]>
                                <xsl:value-of select="name"/>
                                <![CDATA[ </h1> ]]>
                                <![CDATA[ <p>]]>
                                <xsl:value-of select="name"/> has a population of 

                                <xsl:value-of select="format-number(population,'#,000')"/>. Their currency is called the 

                                <xsl:value-of select="currency"/> and their spoken language is 

                                <xsl:value-of select="official_language"/> Their capital is called 

                                <xsl:value-of select="capital"/>
                                <![CDATA[</p><p> ]]>
                                <xsl:value-of select="interesting_fact"/>
                                <![CDATA[ </p> ]]>
                                </xsl:attribute>
                            <xsl:value-of select="name"/>
                        </button>
                    </xsl:for-each>
                </div>
                <div id="demo"/>
                <script>
                    function myFunction(clicked_object)
                        {
                            var x = clicked_object.getAttribute('value');
                            document.getElementById("demo").innerHTML = x;
                         }
            </script>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

#挑选{
位置:绝对位置;
左:0;
排名:0;
背景色:黑色;
宽度:20%;
身高:100%
}
h1{
颜色:白色;
文本对齐:居中;
}
氢{
颜色:白色;
}
a{
颜色:白色;
}
#演示{
位置:绝对位置;
左:20%;
排名:0;
宽度:80%;
身高:100%;
}
钮扣{
背景色:透明;
背景重复:无重复;
边界:无;