<xsl:key name="workcds" match="cd/playlist/work" use="." />
<xsl:for-each select="cd/playlist/work">
<work>
<xsl:attribute name="id">
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
<xsl:attribute name="first">
<xsl:value-of select="generate-id(key('workcds',.)[1])"/>
</xsl:attribute>
<xsl:value-of select="."/>
</work>
</xsl:for-each>
. . .
<work id="d0e43778" first="d0e43778">Waiter, make mine blues</work>
<work id="d0e43781" first="d0e7452">What is this thing called love?</work>
<work id="d0e43807" first="d0e17267">Opus one</work>