If you have
<xsl:variable name="type">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
then you need e.g. <xsl:copy-of select="$type/type/id"/>
to copy the id
element as the type
variable is bound to a temporary document node containing a type
element node with an id
child element node.
Or use
<xsl:variable name="type" as="element()">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
then <xsl:copy-of select="$type/id"/>
works, as now the variable is bound to the type
element node.
Here is a complete sample with my suggestions:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:variable name="test1">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
<TEST1><xsl:copy-of select="$test1/type/id"/></TEST1>
<xsl:variable name="test2" as="element()">
<type>
<label>Book</label>
<id>book</id>
</type>
</xsl:variable>
<TEST2><xsl:copy-of select="$test2/id"/></TEST2>
</xsl:template>
</xsl:stylesheet>
output is
<TEST1>
<id>book</id>
</TEST1>
<TEST2>
<id>book</id>
</TEST2>