xsl-list
[Top] [All Lists]

[xsl] XSLT1.0 distinct list of attributes across several nodes

2018-06-25 13:52:12
I'm restricted to XSLT1.0 with no extensions.
I need to get a list of distinct attributes across a set of nodes.

From the simplified XML below, the result should be 1,2,3,5 for the first 
post_press_version (25) and 1,2,3,6 for the second (26)

<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>
I tried the XSL below, but it only returns 1,2,3: the results of the first 
hopper node in the first hopper_sequence
   <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>

I'm struggling to figure out where I'm going wrong. I also tried the Meunchen 
method with this key, but get similar results

<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)"/>

Any suggestions?
Thanks
Mark


a Segerdahl company
Mark Anderson
Director of ERP Systems
Phone: 847-419-3329
Mobile: 13125764332
Email: mark(_dot_)anderson(_at_)sg360(_dot_)com
www.sg360.com
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

JPEG image

<Prev in Thread] Current Thread [Next in Thread>