0

The given XML:

<records>
    <record>
        <country>Germany</country>
        <value>123</value>
    </record>
    <record>
        <country>Germany</country>
        <value>62</value>
    </record>
    <record>
        <country>Germany</country>
        <value>033</value>
    </record>
    <record>
        <country>Armenia</country>
        <value>444</value>
    </record>
    <record>
        <country>Armenia</country>
        <value>212</value>
    </record>
    <record>
        <country>Armenia</country>
        <value>864</value>
    </record>
</records>

How do I get an output, which respectively chooses every first occurrence of <record> by the value of <country>.

So the desired output should look like:

<records>
    <record>
        <country>Germany</country>
        <value>123</value>
    </record>
    <record>
        <country>Armenia</country>
        <value>444</value>
    </record>
</records>

UPDATE: Solved my Problem with given XSL

<xsl:key name="country" match="record" use="value" />

<xsl:template match="records">
    <xsl:apply-templates select="record[1]" />
</xsl:template>

<xsl:template match="record">
    <xsl:for-each select="key('country', value)">
        <country><xsl:value-of select="country"/></country>
        <value><xsl:value-of select="value"/></value>
    </xsl:for-each>
</xsl:template>
d3tr0id
  • 1
  • 1
  • This is a *grouping* question. Do a search - it's probably the most often asked XSLT question here. Note that answers are different for XSLT 1.0 or 2.0. – michael.hor257k Jun 22 '20 at 14:53
  • You can take a look at this answer : https://stackoverflow.com/questions/2146648/how-to-apply-group-by-on-xslt-elements – Sebastien Jun 22 '20 at 15:09

0 Answers0