Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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 创建xml属性值的下拉列表_Javascript_Html_Xml_Xslt_Xpath - Fatal编程技术网

Javascript 创建xml属性值的下拉列表

Javascript 创建xml属性值的下拉列表,javascript,html,xml,xslt,xpath,Javascript,Html,Xml,Xslt,Xpath,这是我的xml文件:- <child_2 entity_id="2" value="Root" parent_id="1"> <child_4 entity_id="4" value="Activities" parent_id="2"> <child_10066 entity_id="10066" value="Physical1" parent_id="4"> <child_10067 entity_i

这是我的xml文件:-

<child_2 entity_id="2" value="Root" parent_id="1">
    <child_4 entity_id="4" value="Activities" parent_id="2">
        <child_10066 entity_id="10066" value="Physical1" parent_id="4">
            <child_10067 entity_id="10067" value="Cricket" parent_id="10066">
                <child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
            </child_10067>
        </child_10066>
        <child_10069 entity_id="10069" value="Test2" parent_id="4"/>
        <child_10070 entity_id="10070" value="Test3" parent_id="4"/>
        <child_10071 entity_id="10071" value="Test4" parent_id="4"/>
        <child_10072 entity_id="10072" value="Test5" parent_id="4"/>
        <child_5 entity_id="5" value="Physical" parent_id="4"/>
    </child_4>
</child_2>
这是我的xslt:-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes"/>
  <xsl:key name="kType" match="child_2" use="value"/>
  <xsl:template match="/">
  <select name="productGroup" id="productGroup">
      <xsl:apply-templates 
        select="child_2/child_4[generate-id() = 
                                 generate-id(key('kGroup', group)[1])]" />
    </select>
 </xsl:template>
 <xsl:template match="child_2">
 <option value="[@value]">
    <xsl:value-of select="@value"/>
</option>
</xsl:template>
</xsl:stylesheet>

这里有一个选项:

样式表

输入

输出

活动
物理1
板球
有一天
测试2
测试3
测试4
测试5
物理的

您是否对涉及的每一个步骤都一窍不通?我正在尝试一些xslt代码。。。检查我编辑的问题。。。请
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes"/>
  <xsl:key name="kType" match="child_2" use="value"/>
  <xsl:template match="/">
  <select name="productGroup" id="productGroup">
      <xsl:apply-templates 
        select="child_2/child_4[generate-id() = 
                                 generate-id(key('kGroup', group)[1])]" />
    </select>
 </xsl:template>
 <xsl:template match="child_2">
 <option value="[@value]">
    <xsl:value-of select="@value"/>
</option>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="child_4">
    <!--
    Retained @name and @id attributes because they were in your original XSLT code
    -->
    <select name="productGroup" id="productGroup">
      <!-- Apply the @value attribute on this element and all its descendants -->
      <xsl:apply-templates select="descendant-or-self::*/@value"/>
    </select>
  </xsl:template>

  <xsl:template match="@value">
    <option>
      <xsl:value-of select="."/>
    </option>
  </xsl:template>
</xsl:stylesheet>
<child_2 entity_id="2" value="Root" parent_id="1">
  <child_4 entity_id="4" value="Activities" parent_id="2">
    <child_10066 entity_id="10066" value="Physical1" parent_id="4">
      <child_10067 entity_id="10067" value="Cricket" parent_id="10066">
        <child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
      </child_10067>
    </child_10066>
    <child_10069 entity_id="10069" value="Test2" parent_id="4"/>
    <child_10070 entity_id="10070" value="Test3" parent_id="4"/>
    <child_10071 entity_id="10071" value="Test4" parent_id="4"/>
    <child_10072 entity_id="10072" value="Test5" parent_id="4"/>
    <child_5 entity_id="5" value="Physical" parent_id="4"/>
  </child_4>
</child_2>
<select name="productGroup" id="productGroup">
  <option>Activities</option>
  <option>Physical1</option>
  <option>Cricket</option>
  <option>One Day</option>
  <option>Test2</option>
  <option>Test3</option>
  <option>Test4</option>
  <option>Test5</option>
  <option>Physical</option>
</select>