Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server.
Browse by Tags · View All
XML 112
TSQL 69
XQuery 69
XQuery Functions 67
XQuery Training 65
XQuery in TSQL 64
XQuery Tutorial 63
SQL Server XQuery 63
XQuery-Labs 57
BRH 38

Archive · View All
September 2008 32
August 2008 30
July 2008 21
August 2009 19
June 2009 19
May 2010 18
January 2009 15
January 2010 14
October 2008 14
June 2008 13

XQuery Lab 16 - How to modify an attribute specified by a variable?

Aug 8 2008 12:53AM by Jacob Sebastian   

 

In Lab 15, we saw how to modify an attribute based on the value of a variable. We used the value of a variable to locate the correct element. We located the element having a specific attribute with the value specified in a variable.

Now let us look at a bit more complex example. Assume a case where we don't know which attribute to modify. The attribute to be modified is passed to our code as a parameter. So we have a string parameter that stores the name of the attribute to be modified. Let us look at an example.

DECLARE @x XML
SELECT @x = '
<Employees>
<Employee FirstName="Jacob" MiddleName="V" LastName="Sebastian"/>
</Employees>'


DECLARE @var VARCHAR(20)
DECLARE @val VARCHAR(20)

SELECT @var = 'MiddleName'
SELECT @val = 'J'

The task to modify the attribute specified by variable @var and replace the value with the value specified by variable @v. After we update, the attribute "MiddleName" should be replaced with value "J". Let us see the code.

DECLARE @x XML
SELECT @x = '
<Employees>
<Employee FirstName="Jacob" MiddleName="V" LastName="Sebastian"/>
</Employees>'


DECLARE @var VARCHAR(20)
DECLARE @val VARCHAR(20)

SELECT @var = 'MiddleName'
SELECT @val = 'J'


SET @x.modify('
replace value of (
/Employees/Employee/@*[local-name()=sql:variable("@var")]
)[1]
with sql:variable("@val")
'
)

select @x

/*
<Employees>
<Employee FirstName="Jacob" MiddleName="J" LastName="Sebastian" />
</Employees>
*/


XQuery Labs - A Collection of XQuery Sample Scripts

Tags: XQuery-Labs, XML, XQuery, XQuery Functions, SQL Server XQuery, XQuery in TSQL, XQuery Training, XQuery Tutorial,


Jacob Sebastian
1 · 100% · 32004
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"XQuery Lab 16 - How to modify an attribute specified by a variable?" rated 5 out of 5 by 1 readers
XQuery Lab 16 - How to modify an attribute specified by a variable? , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]