I think I might tackle this by first transforming your second XML document to create a stylesheet, and then running this stylesheet with the first XML document as input. So you task becomes one of transforming
Code:
<variable name="template">
<Authordetails>
<author/>
<place/>
<book name=""/> //here the value should go in attribute
</authordetails>
</variable>
to something like
Code:
<xsl:template match="/"
<Authordetails>
<author><xsl:value-of select="author/name"/></author>
<place><xsl:value-of select="author/name"/></place>
<book name="{author/book}"/>
</Authordetails>
</xsl:template>
What isn't clear to me is how you know the intended mapping, for example how do you know that <author> in the output should contain the value tagged as <name> in the input?