xslt to remove duplicates entries using Muenchian grouping

后端 未结 1 1201
予麋鹿
予麋鹿 2021-01-24 12:46

I am trying to display all s of node. But I don\'t want to display duplicate entries of department from

相关标签:
1条回答
  • 2021-01-24 13:40

    You need a second level of Muenchian grouping - you already have a key that finds unique company names, you now need a second key that finds unique company-department pairs:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="html" />
    
        <xsl:key name="companyname" match="company" use="companyname"/>
        <xsl:key name="companyDepartment" match="company"
                 use="concat(companyname, '|', department)" />
    
        <xsl:template match="/">
            <xsl:for-each select="/employee_data/employeedetails/company[generate-id() = generate-id(key('companyname', companyname)[1])]">
                <tr>
                    <td>
                        <xsl:value-of select="@id"/>
                    </td>
                    <td>
                        <xsl:apply-templates select="key('companyname', companyname)
                              [generate-id() = generate-id(key('companyDepartment',
                                  concat(companyname, '|', department))[1])]" />
                    </td>
                </tr>
            </xsl:for-each>
        </xsl:template>
    
        <xsl:template match="company">
            <xsl:value-of select="department" />
            <br />
        </xsl:template>
    </xsl:stylesheet>
    

    This filters the list of all company elements matching the current companyname so you just get the first mention of each department.

    0 讨论(0)
提交回复
热议问题