internal int InsertVariable(VariableAction variable)
{
InputScope varScope;
if (variable.IsGlobal)
{
Debug.Assert(_rootAction != null);
varScope = _rootScope;
}
else
{
Debug.Assert(_currentTemplate != null);
Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter);
varScope = _scopeManager.VariableScope;
}
VariableAction oldVar = varScope.ResolveVariable(variable.Name);
if (oldVar != null)
{
// Other variable with this name is visible in this scope
if (oldVar.IsGlobal)
{
if (variable.IsGlobal)
{
// Global Vars replace each other base on import presidens odred
if (variable.Stylesheetid == oldVar.Stylesheetid)
{
// Both vars are in the same stylesheet
throw XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
}
else if (variable.Stylesheetid < oldVar.Stylesheetid)
{
// newly defined var is more importent
varScope.InsertVariable(variable);
return oldVar.VarKey;
}
else
{
// we egnore new variable
return InvalidQueryKey; // We didn't add this var, so doesn't matter what VarKey we return;
}
}
else
{
// local variable can shadow global
}
}
else
{
// Local variable never can be "shadowed"
throw XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
}
}
varScope.InsertVariable(variable);
return _currentTemplate.AllocateVariableSlot();
}