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 57 58 59 60 61 62 63 64 65 66
| <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="data" select="'Courant.xml'" />
<xsl:param name="dic" select="document($data)/Courant" />
<xsl:template match="*|text()|@*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="*|text()|@*|comment()|processing-instruction()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Article">
<xsl:copy>
<xsl:if test="@ID">
<xsl:copy-of select="@ID" />
<xsl:choose>
<xsl:when test="$dic/Article/id[.=current()/@ID]">
<xsl:call-template name="proc_attr">
<xsl:with-param name="attr_node" select="@Theme1" />
<xsl:with-param name="attr_newname" select="'Theme1'" />
<xsl:with-param name="node" select="$dic/Article/id[.=current()/@ID]/following-sibling::Theme1" />
</xsl:call-template>
<xsl:call-template name="proc_attr">
<xsl:with-param name="attr_node" select="@Theme2" />
<xsl:with-param name="attr_newname" select="'Theme2'" />
<xsl:with-param name="node" select="$dic/Article/id[.=current()/@ID]/following-sibling::Theme2" />
</xsl:call-template>
<xsl:call-template name="proc_attr">
<xsl:with-param name="attr_node" select="@Theme3" />
<xsl:with-param name="attr_newname" select="'Theme3'" />
<xsl:with-param name="node" select="$dic/Article/id[.=current()/@ID]/following-sibling::Theme3" />
</xsl:call-template>
<xsl:apply-templates select="@*[name()!='ID' and name()!='Theme1' and name()!='Theme2' and name()!='Theme3']" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*[name() != 'ID']" />
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="*|text()|comment()|processing-instruction()" />
</xsl:if>
<xsl:if test="not(@ID)">
<xsl:apply-templates select="*|text()|@*|comment()|processing-instruction()" />
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template name="proc_attr">
<xsl:param name="attr_node" />
<xsl:param name="attr_newname" />
<xsl:param name="node" />
<xsl:if test="$attr_node">
<xsl:choose>
<xsl:when test="$node">
<xsl:attribute name="{$attr_newname}">
<xsl:value-of select="$node" />
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$attr_node" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet> |