I'm reading a mapping table into a stylesheet like this:

<xsl:variable name="mappingtable"

Then inside a template I'm doing a for-each:

<xsl:template match="input/add|input/instance">
<xsl:for-each select="$mappingtable//row">
<xsl:call-template name="output-field">
<xsl:with-param name="field-name" select="col[1]"/>
<xsl:with-param name="start" select="col[2]"/>
<xsl:with-param name="end" select="col[3]"/>
<xsl:template name="output-field">
<xslaram name="field-name"/>
<xslaram name="start"/>
<xslaram name="end"/>
<xsl:variable name="field-value" select="//*[(@attr-name =

The problem is when I'm inside the for-each the <xsl:variable
name="field-value" select="*[(@attr-name = $field-name)][1]/value[1]"/>
doesn't work anymore.

I have tried with //*[(@attr-name = $field-name)][1]/value[1] but that
doesn't work and I think I know why.

The workaround is to set a global variable <xsl:variable name="xds"
select="."/> in the beginning of the stylesheet and then use
$xds//*[(@attr-name = $field-name)][1]/value[1] in the output-field

Now to the question:
Is there a proper way to do this or a better/nicer way?