XSLT1.0跨多个节点的不同属性列表

时间:2018-06-21 22:01:56

标签: xslt-1.0

我坚持使用XSLT1.0,没有扩展名。

我需要获取属性不同的节点列表。在下面的XML中,第一个post_press_version(25)的结果应该是1,2,3,5,第二个post_press_version(26)的结果应该是1,2,3,6

<order>
<post_press_version>
    <post_press_version_id>25</post_press_version_id>
    <hopper_allocations>
        <hopper_sequence>
            <sequence_id>2</sequence_id>
            <sequence_part_produced_id>37</sequence_part_produced_id>
            <sequence_part_produced_name>96854-12WS10</sequence_part_produced_name>
            <sequence_qty>2</sequence_qty>
            <hopper number="0" id="" is_insert="False"/>
            <hopper number="1" id="23" is_insert="False">96854-6FL</hopper>
            <hopper number="2" id="13" is_insert="False">96854-8FL003</hopper>
            <hopper number="3" id="15" is_insert="False">96854-10FL004</hopper>
            <hopper number="4" id="" is_insert="False"/>
            <hopper number="5" id="" is_insert="False"/>
            <hopper number="6" id="" is_insert="False"/>
        </hopper_sequence>
        <hopper_sequence>
            <sequence_id>3</sequence_id>
            <sequence_part_produced_id>38</sequence_part_produced_id>
            <sequence_part_produced_name>96854-12WS20</sequence_part_produced_name>
            <sequence_qty>250</sequence_qty>
            <hopper number="0" id="" is_insert="False"/>
            <hopper number="1" id="24" is_insert="False">96854-6FL10</hopper>
            <hopper number="2" id="29" is_insert="False">96854-8FL</hopper>
            <hopper number="3" id="" is_insert="False"/>
            <hopper number="4" id="" is_insert="False"/>
            <hopper number="5" id="31" is_insert="False">96854-10FL</hopper>
            <hopper number="6" id="" is_insert="False"/>
        </hopper_sequence>
    </hopper_allocations>
</post_press_version>
<post_press_version>
    <post_press_version_id>26</post_press_version_id>
    <hopper_allocations>
        <hopper_sequence>
            <sequence_id>2</sequence_id>
            <sequence_part_produced_id>37</sequence_part_produced_id>
            <sequence_part_produced_name>96854-12WS10</sequence_part_produced_name>
            <sequence_qty>2</sequence_qty>
            <hopper number="0" id="" is_insert="False"/>
            <hopper number="1" id="23" is_insert="False">96854-6FL</hopper>
            <hopper number="2" id="13" is_insert="False">96854-8FL003</hopper>
            <hopper number="3" id="15" is_insert="False">96854-10FL004</hopper>
            <hopper number="4" id="" is_insert="False"/>
            <hopper number="5" id="" is_insert="False"/>
            <hopper number="6" id="" is_insert="False"/>
        </hopper_sequence>
        <hopper_sequence>
            <sequence_id>3</sequence_id>
            <sequence_part_produced_id>38</sequence_part_produced_id>
            <sequence_part_produced_name>96854-12WS20</sequence_part_produced_name>
            <sequence_qty>250</sequence_qty>
            <hopper number="0" id="" is_insert="False"/>
            <hopper number="1" id="24" is_insert="False">96854-6FL10</hopper>
            <hopper number="2" id="29" is_insert="False">96854-8FL</hopper>
            <hopper number="3" id="" is_insert="False"/>
            <hopper number="4" id="" is_insert="False"/>
            <hopper number="5" id="31" is_insert="False"/>
            <hopper number="6" id="" is_insert="False">96854-10FL</hopper>
        </hopper_sequence>
    </hopper_allocations>
</post_press_version>

我在下面尝试了XSL,但它只返回1,2,3:第一个hopper_sequence中第一个hopper节点的结果

   <xsl:template match="order">
        <html>
            <body>
                <xsl:for-each
                    select="/order/post_press_version/hopper_allocations/hopper_sequence/hopper[node() and not(@number = preceding::hopper/@number)]]">
                    <p>
                        <xsl:value-of select="../../../post_press_version_id"/>-<xsl:value-of select="@number"/>
                    </p>
                </xsl:for-each>
            </body>
        </html>

    </xsl:template>

我正在努力弄清楚哪里错了。我也尝试过使用此密钥的Meunchen方法,但得到相似的结果

<xsl:key name="unique_post_press_version_hoppers" match="/order/post_press_version/hopper_allocations/hopper_sequence/hopper" use="concat(../../../post_press_version_id, @number)"/>

有什么建议吗?

谢谢

标记

1 个答案:

答案 0 :(得分:0)

我更新并使用了XML,并根据需要找到合适的输出。请再看一次它是正确的。只有零来了。