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
| <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="affiche-xpath">
<xsl:with-param name="element" select="test/oui[2]"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="affiche-xpath">
<xsl:param name="element"/>
<xsl:param name="xpath"/>
<xsl:choose>
<xsl:when test="$element/parent::node()">
<!-- Détermination du rang -->
<xsl:variable name="rang" select="count($element/preceding-sibling::*[name() = name($element)]) + 1"/>
<xsl:call-template name="affiche-xpath">
<xsl:with-param name="element" select="$element/parent::*"/>
<xsl:with-param name="xpath">
<xsl:value-of select="concat('/', name($element))"/>
<xsl:if test="$rang > 1">
<xsl:value-of select="concat('[', $rang, ']')"/>
</xsl:if>
<xsl:value-of select="$xpath"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$xpath"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> |
Partager