Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:40:51+00:00 2026-05-19T22:40:51+00:00

I am new to XSLT and have a problem with removing duplicate entries from

  • 0

I am new to XSLT and have a problem with removing duplicate entries from the output.

The example XML-File:

<Datenaustausch>
<Meldung>
    <Anfallstelle>
        <AS>
            <ASStamm>
                <ASNR>009803336</ASNR>
                <ASENF>false</ASENF>
                <ASInaktiv>false</ASInaktiv>
            </ASStamm>
            <ASDaten>
                <ASMeldung>
                    <ASGueltigAb>2003-04-25</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
                <ASMeldung>
                    <ASGueltigAb>2008-05-15</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
                <ASMeldung>
                    <ASGueltigAb>2010-08-20</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>40x</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
            </ASDaten>
        </AS>
        <AS>
            <ASStamm>
                <ASNR>031630116</ASNR>
                <ASENF>false</ASENF>
                <ASInaktiv>false</ASInaktiv>
            </ASStamm>
            <ASDaten>
                <ASMeldung>
                    <ASGueltigAb>2009-04-21</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>400</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
            </ASDaten>
        </AS>
        <AS>
            <ASStamm>
                <ASNR>040917889</ASNR>
                <ASENF>false</ASENF>
                <ASInaktiv>false</ASInaktiv>
            </ASStamm>
            <ASDaten>
                <ASMeldung>
                    <ASGueltigAb>2007-11-15</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>400</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>42x</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
                <ASMeldung>
                    <ASGueltigAb>2009-01-19</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>400</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>42x</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
                <ASMeldung>
                    <ASGueltigAb>2010-06-25</ASGueltigAb>
                    <ASMldData>
                        <ASLizData>
                            <ASFrk>400</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>42x</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                        <ASLizData>
                            <ASFrk>8xx</ASFrk>
                            <ASLizGrad>100</ASLizGrad>
                            <ASAntVerp>100</ASAntVerp>
                        </ASLizData>
                    </ASMldData>
                </ASMeldung>
            </ASDaten>
        </AS>
                    <AS>
                    ....
                    </AS>
        </Anfallstelle>
</Meldung>
</Datenaustausch>

.... represents more orders of same as above

I need to get this output:

From every ‘ASStamm’ where the ID is the ‘ASNR’ I what to remove the duplicate entries (‘ASFrk’) with the oldest date (‘ASGueltigAb’).

For example the first ‘AS’ entry should look like this:

       <tr>
            <td>009803336</td>
            <td>8xx</td>
            <td>100</td>
            <td>100</td>
            <td>2008-05-15</td>
        </tr>
        <tr>
            <td>009803336</td>
            <td>40x</td>
            <td>100</td>
            <td>100</td>
            <td>2010-08-20</td>
        </tr>

The duplicate entry (with ‘ASFrk’ (8xx) and the old date ‘ASGueltigAb’ (2003-04-25)) was removed.

At the moment I use this “solution” to transform the xml to a html table, but without removing the duplicate entries.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <html>
            <head>
                <title>XML</title>
            </head>
            <body>
                <table border="1">
                   <tr>
                        <th>ASNR</th>
                        <th>ASFrk</th>
                        <th>ASLizGrad</th>
                        <th>ASAntVerp</th>
                        <th>ASGueltigAb</th>
                    </tr>
                    <xsl:for-each select="/Datenaustausch/Meldung/Anfallstelle/AS">
                        <xsl:sort select="ASStamm/ASNR" data-type="number"/>
                        <xsl:for-each select="ASDaten/ASMeldung">
                            <xsl:sort select="ASMldData/ASLizData/ASFrk" order="descending"/>
                            <xsl:sort select="ASGueltigAb" order="descending"  />
                            <tr>
                                <td>
                                    <xsl:value-of select="parent::*/parent::AS/ASStamm/ASNR"/>
                                </td>
                                <td>
                                    <xsl:value-of select="ASMldData/ASLizData/ASFrk"/>
                                </td>
                                <td>
                                    <xsl:value-of select="ASMldData/ASLizData/ASLizGrad"/>
                                </td>
                                <td>
                                    <xsl:value-of select="ASMldData/ASLizData/ASAntVerp"/>
                                </td>
                                <td>
                                    <xsl:value-of select="ASGueltigAb"/>
                                </td>
                            </tr>
                        </xsl:for-each>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

HTML Output:

Example 1:
http://img152.imageshack.us/i/xmlex.jpg/

The marked line should be removed for the ‘ASNR’-ID (009803336), for the next example ‘ASNR’-ID (040917889) the two marked lines should be removed.

Example 2:
http://img710.imageshack.us/i/xmlex2.jpg/

I think there is a solution with the use of the “Muenchian grouping”, but i don´t know how.

Can someone please help me to get a solution using XSLT 1.0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:40:51+00:00Added an answer on May 19, 2026 at 10:40 pm

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kASLizDataByASNR-ASFrk"
                 match="ASLizData"
                 use="concat(preceding::ASNR[1],'+',ASFrk)"/>
        <xsl:template match="text()"/>
        <xsl:template match="/">
            <html>
                <head>
                    <title>XML</title>
                </head>
                <body>
                    <table border="1">
                        <tr>
                            <th>ASNR</th>
                            <th>ASFrk</th>
                            <th>ASLizGrad</th>
                            <th>ASAntVerp</th>
                            <th>ASGueltigAb</th>
                        </tr>
                        <xsl:apply-templates/>
                    </table>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="ASLizData[
                                count(
                                   .|key('kASLizDataByASNR-ASFrk',
                                         concat(preceding::ASNR[1],'+',ASFrk)
                                     )[1]
                                ) = 1
                             ]">
            <xsl:variable name="vASNR" select="preceding::ASNR[1]"/>
            <xsl:for-each select="key('kASLizDataByASNR-ASFrk',
                                      concat($vASNR,'+',ASFrk)
                                  )">
                <xsl:sort select="../../ASGueltigAb" order="descending"/>
                <xsl:if test="position()=1">
                    <tr>
                        <td>
                            <xsl:value-of select="$vASNR"/>
                        </td>
                        <xsl:apply-templates mode="cell"/>
                        <td>
                            <xsl:value-of select="../../ASGueltigAb"/>
                        </td>
                    </tr>
                </xsl:if>
            </xsl:for-each>
        </xsl:template>
        <xsl:template match="ASLizData/*" mode="cell">
            <td>
                <xsl:value-of select="."/>
            </td>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <html>
        <head>
            <META http-equiv="Content-Type" content="text/html; charset=UTF-16">
            <title>XML</title>
        </head>
        <body>
            <table border="1">
                <tr>
                    <th>ASNR</th>
                    <th>ASFrk</th>
                    <th>ASLizGrad</th>
                    <th>ASAntVerp</th>
                    <th>ASGueltigAb</th>
                </tr>
                <tr>
                    <td>009803336</td>
                    <td>8xx</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2010-08-20</td>
                </tr>
                <tr>
                    <td>009803336</td>
                    <td>40x</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2010-08-20</td>
                </tr>
                <tr>
                    <td>031630116</td>
                    <td>400</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2009-04-21</td>
                </tr>
                <tr>
                    <td>031630116</td>
                    <td>8xx</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2009-04-21</td>
                </tr>
                <tr>
                    <td>040917889</td>
                    <td>400</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2010-06-25</td>
                </tr>
                <tr>
                    <td>040917889</td>
                    <td>42x</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2010-06-25</td>
                </tr>
                <tr>
                    <td>040917889</td>
                    <td>8xx</td>
                    <td>100</td>
                    <td>100</td>
                    <td>2010-06-25</td>
                </tr>
            </table>
        </body>
    </html>
    

    Note: Key by ASNR and ASFrk. Maximum for-each.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to XML & XSLT but have got this problem. I have
i am pretty new to XSLT / XML and HTML. I have a XML
I am new in xslt. I have the following problem. I need within an
I am new to XSLT, please help. We have an XML which we want
I currently have a string builder taking the output from an in-memory XSLT transformation.
I'm very new to XML and XSLT. I have a homework assignment that asks
I want to change from one XML (XHTML) file to another using XSLT. In
Can any one help in transforming my xml though XSLT. I am new to
New to PHP and MySQL, have heard amazing things about this website from Leo
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.