1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
<xsl:param name="sep" select="'|'" />
<xsl:key name="id-g" match="Employee" use="ID" />
<xsl:key name="id-wid-g" match="Employee" use="concat(ID, $sep, WeekID)" />
<xsl:key name="id-wid-did-g" match="Employee" use="concat(ID, $sep, WeekID, $sep, DayID)" />
<xsl:template match="Employees">
<xsl:copy>
<xsl:apply-templates select="Employee" />
</xsl:copy>
</xsl:template>
<xsl:template match="Employee[generate-id()=generate-id(key('id-g',ID)[1])]">
<xsl:variable name="id" select="ID" />
<xsl:copy>
<ID><xsl:value-of select="$id" /></ID>
<Weeks>
<xsl:for-each select="/Employees/Employee[ID=$id]/WeekID">
<xsl:apply-templates select="." />
</xsl:for-each>
</Weeks>
</xsl:copy>
</xsl:template>
<xsl:template match="WeekID[generate-id(parent::Employee)=generate-id(key('id-wid-g',concat(preceding-sibling::ID,$sep,.))[1])]">
<xsl:variable name="id" select="preceding-sibling::ID" />
<xsl:variable name="wid" select="." />
<Week>
<WeekID><xsl:value-of select="$wid" /></WeekID>
<Days>
<xsl:for-each select="/Employees/Employee[ID=$id and WeekID=$wid]/DayID">
<xsl:apply-templates select="." />
</xsl:for-each>
</Days>
</Week>
</xsl:template>
<xsl:template match="DayID[generate-id(parent::Employee)=generate-id(key('id-wid-did-g',concat(preceding-sibling::ID,$sep,preceding-sibling::WeekID,$sep,.))[1])]">
<xsl:variable name="id" select="preceding-sibling::ID" />
<xsl:variable name="wid" select="preceding-sibling::WeekID" />
<xsl:variable name="did" select="." />
<Day>
<DayID><xsl:value-of select="$did" /></DayID>
<xsl:for-each select="/Employees/Employee[ID=$id and WeekID=$wid and DayID=$did]/Hours">
<Hours><xsl:value-of select="." /></Hours>
</xsl:for-each>
</Day>
</xsl:template>
<xsl:template match="Employee" />
<xsl:template match="WeekID" />
<xsl:template match="DayID" />
</xsl:stylesheet> |
Partager