xsl:for-each,然后xsl:相同元素的值?

时间:2017-06-26 21:04:39

标签: xml xslt

我可以在使用for-each调用元素之后拉取元素的值。

输入

        <draft_mac_data>
      <maintenance_function justification="center">Setup</maintenance_function>
      <maintenance_level_c justification="center">10.00</maintenance_level_c>
      <tools_test_equipment_codes>
        <tools_test_equipment_reference_code>42</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>48</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>49</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>78</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>100</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>101</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>114</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>117</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>124</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>128</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>151</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>165</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>169</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>176</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>177</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>196</tools_test_equipment_reference_code>
        <tools_test_equipment_reference_code>235</tools_test_equipment_reference_code>
      </tools_test_equipment_codes>
    </draft_mac_data>

XSLT剪辑:

<qualify-2lvl>
                        <maintfunc><xsl:attribute name="func"><xsl:value-of select="doc:maintenance_function"/></xsl:attribute></maintfunc>
                        <xsl:for-each select="doc:maintenance_level_c">
                            <maintclass-2lvl>
                                <c><xsl:value-of select="doc:maintenance_level_c"/></c>
                            </maintclass-2lvl>
                        </xsl:for-each>
                        <xsl:for-each select="doc:maintenance_level_f">
                            <maintclass-2lvl>
                                <f><xsl:value-of select="doc:maintenance_level_f"/></f>
                            </maintclass-2lvl>
                        </xsl:for-each>
                        <xsl:for-each select="doc:maintenance_level_h">
                            <maintclass-2lvl>
                                <h><xsl:value-of select="doc:maintenance_level_h"/></h>
                            </maintclass-2lvl>
                        </xsl:for-each>
                        <xsl:for-each select="doc:maintenance_level_d">
                            <maintclass-2lvl>
                                <d><xsl:value-of select="doc:maintenance_level_d"/></d>
                            </maintclass-2lvl>
                        </xsl:for-each> 
                        <xsl:for-each select="doc:tools_test_equipment_codes/doc:tools_test_equipment_reference_code">
                            <trefs>
                            <tref><xsl:attribute name="refs"><xsl:value-of select="concat('teref', doc:tools_test_equipment_reference_code)"/></xsl:attribute></tref>
                            </trefs>
                        </xsl:for-each>
                </qualify-2lvl>

输出

        <qualify-2lvl>
      <maintfunc func="Load / Unload"/>
      <maintclass-2lvl>
        <c/>
      </maintclass-2lvl>
      <trefs>
        <tref refs="teref"/>
      </trefs>
      <trefs>
        <tref refs="teref"/>
      </trefs>
      <trefs>
        <tref refs="teref"/>
      </trefs>
      <trefs>
        <tref refs="teref"/>
      </trefs>
      <trefs>
        <tref refs="teref"/>
      </trefs>
    </qualify-2lvl>
例如

。我想对每个 tools_test_equipment_reference_code元素 说,创建 并使用 tools_test_equipment_reference_code元素 <的值填充 refs 属性/强>

有更精确的方法吗?我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

foreach($rings as $ringIndex => $ring){ $var = $ringIndex === 1 ? 'shell' : 'hole'; $$var = $this->getPolygonFromRing($ring); } 内部节点内部是该元素,因此要使用xsl:for-each select="doc:maintenance_level_c"输出其值。