<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="items/item">
<xsl:sort data-type="number" select="@d" />
<xsl:sort />
<xsl:if test="position() <= 3">
<!-- Собственно вывод -->
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>