Compteur à l'intérieur de xsl:for-each boucle

Comment obtenir un compteur à l'intérieur de xsl:for-each boucle de manière à refléter le nombre d'élément en cours de traitement.

Par exemple, pour ma source XML est

<books>
    <book>
        <title>The Unbearable Lightness of Being </title>
    </book>
    <book>
        <title>Narcissus and Goldmund</title>
    </book>
    <book>
        <title>Choke</title>
    </book>
</books>

Ce que je veux obtenir est:

<newBooks>
    <newBook>
        <countNo>1</countNo>
        <title>The Unbearable Lightness of Being </title>
    </newBook>
    <newBook>
        <countNo>2</countNo>
        <title>Narcissus and Goldmund</title>
    </newBook>
    <newBook>
        <countNo>3</countNo>
        <title>Choke</title>
    </newBook>
</newBooks>

La transformation XSLT à modifier:

<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:template match="/">
        <newBooks>
            <xsl:for-each select="books/book">
                <newBook>
                    <countNo>???</countNo>
                    <title>
                        <xsl:value-of select="title"/>
                    </title>
                </newBook>
            </xsl:for-each>
        </newBooks>
    </xsl:template>
</xsl:stylesheet>

Donc, la question est de savoir quoi mettre à la place de ???. Est-il un mot-clé standard ou dois-je simplement devez déclarer une variable et de l'incrémenter à l'intérieur de la boucle?

Que la question est assez long, je devrais sans doute s'attendre à une ligne ou un mot de réponse 🙂

InformationsquelleAutor kristof | 2008-09-18