As stated in the comments this is quite easy, but ill advised. However, if you acknowledge that it is ill-advised, then there is no reason to show how.
Firstly, in XSLT there are two ways to create an element, by placing the element inline:
<xsl:template match="book">
    <book1>
        <!-- Some stuff -->
    </book1>
<xsl:template>
Or programatically using the xsl:element directive:
<xsl:template match="book">
    <xsl:element name="book1">
        <!-- Some stuff -->
    </xsl:element>
<xsl:template>
The @name attribute in the above code can take an XPath expression if we use an attribute value template. Which means we can insert a dynamic value in there:
<xsl:template match="book">
    <xsl:element name="book{//some/xpath/here()}">
        <!-- Some stuff -->
    </xsl:element>
<xsl:template>
Additionally, we can get the position of the current node based on the current context using the position() Xpath function:
<xsl:template match="/">
    <xsl:for-each select="//book">
        <!-- this loop will number the books in the whole document 
             because its seaching in all nodes (//). -->
        <xsl:value-of select="position()"/>
    </xsl:for-each>
<xsl:template>
<xsl:template match="library">
    <xsl:for-each select=".//book">
        <!-- this loop will number the books in the current *library*
             because its seaching in all nodes under the library node (.//)  -->
        <xsl:value-of select="position()"/>
    </xsl:for-each>
<xsl:template>
As Michael Kay showed in his answer as I was typing this (grrr), combining these is trivial.