In an xsl:for-each
XPaths are interpreted in the context of the selected "document", i.e. /
refers to node-set($categories)
. You can see for yourself by trying the following code:
<xsl:template match="/">
<xsl:variable name="root" select="/"/>
<result>
<xsl:for-each select="exsl:node-set($categories)/category">
<xsl:element name="{@name}">
<xsl:for-each select="$root/input/object">
<item>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</result>
</xsl:template>
It uses the variable root
to pass access to the document selected by the template to the inner xsl:for-each
loop. (Note: The variable could as well been placed outside of the template.)
You can double-check that /
actually uses the node-set by replacing select="/input/object"
by select="/category"
in your original code. You will get empty items (one per category) in your elements.