What you want is - AFAIK - not possible...
Try to define a working query with your XPath expression:
Btw: Your example is wrong in two ways: Attributs within the XML do not have the @-mark and the closing Parameters-tag is missing its final "s"...
DECLARE @data XML=
'<Object>
<Parameters>
<Parameter Name="a">2</Parameter>
<Parameter Name="b">5</Parameter>
<Parameter Name="c"/>
</Parameters>
</Object>';
--This will not work, because your parts are not singleton
--SELECT Context.Node.value('../Parameter[@Name="a"]/text() + ../Parameter[@Name="b"]/text()','int')
--FROM @data.nodes('/Object/Parameters/Parameter[@Name="c"]') AS Context(Node);
--This works, because I framed both parts with (...)[1]
SELECT Context.Node.value('(../Parameter[@Name="a"]/text())[1] + (../Parameter[@Name="b"]/text())[1]','int')
FROM @data.nodes('/Object/Parameters/Parameter[@Name="c"]') AS Context(Node);
But there might be a workaround, but it's quite hacky and not reliable:
A Stored Procedure creates a dynamic sql statement built up from your parameters and executes this.
Your must-not-be-changed XPath expression will be changed in the way, that a + with a blank to the left and to the right (as well as -, * and /) is replaced in the way, that there is a singleton expression returned. I do not know how complex calculations might be. Check it out...
CREATE PROCEDURE dbo.CalculateXPathExpression
(
@data XML
,@XPathContextNode VARCHAR(MAX)
,@XPathCalculation VARCHAR(MAX)
)
AS
BEGIN
DECLARE @Return INT;
DECLARE @CalcSingleton VARCHAR(MAX)='(' + REPLACE(REPLACE(REPLACE(REPLACE(@XPathCalculation,' + ',')[1] + ('),' - ',')[1] + ('),' * ',')[1] + ('),' / ',')[1] + (') + ')[1]';
DECLARE @Cmd NVARCHAR(MAX)=
'SELECT @Return = Context.Node.value(''' + @CalcSingleton + ''',''int'')
FROM @data.nodes(''' + @XPathContextNode + ''') AS Context(Node);';
EXEC sp_executesql @Cmd, N'@data XML, @Return INT OUTPUT',@data=@data, @Return=@Return OUTPUT;
SELECT @Return;
RETURN;
END
GO
DECLARE @data XML=
'<Object>
<Parameters>
<Parameter Name="a">2</Parameter>
<Parameter Name="b">5</Parameter>
<Parameter Name="c"/>
</Parameters>
</Object>';
DECLARE @XPathContextNode VARCHAR(MAX)='/Object/Parameters/Parameter[@Name="c"]';
DECLARE @XPathCalculation VARCHAR(MAX)='../Parameter[@Name="a"]/text() + ../Parameter[@Name="b"]/text()';
EXEC dbo.CalculateXPathExpression @data, @XPathContextNode, @XPathCalculation;
GO
DROP PROCEDURE dbo.CalculateXPathExpression;
GO