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
| <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="long" match="c" use="string-length(@id)"/>
<xsl:template match="/">
<b>
<xsl:apply-templates select="key('long',1)">
<xsl:with-param name="len" select="2"/>
</xsl:apply-templates>
</b>
</xsl:template>
<xsl:template match="c">
<xsl:param name="len"/>
<xsl:copy>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:choose>
<xsl:when test="key('long',$len)[starts-with(./@id,current()/@id)]">
<xsl:apply-templates select="key('long',$len)[starts-with(./@id,current()/@id)]">
<xsl:with-param name="len" select="$len + 1"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="key('long',($len+1))[starts-with(./@id,current()/@id)]">
<xsl:with-param name="len" select="$len + 2"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> |
Partager