getting variable inside awk

Hi All,

I have awk script for replacing the nth ocurance of a string in an xml file...
My code is like this

FILETYPE=xml
TAGNAME=type
OCCURANCE=$1
TAGVALUE=valueur

echo OCCURANCE:$OCCURANCE
echo TAGNAME:$TAGNAME
echo TAGVALUE:$TAGVALUE

awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/< type(.+)type>/&&n==++c{sub("<type>(.+)</type>",s)}1' application.xml

this is working correctly .. but if ia m replacing the <type tag with $TAGNAME inside singlequotes, its not working...

awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/<$TAGNAME(.+)$TAGNAME>/&&n==++c{sub("<$TAGNAME>(.+)</$TAGNAME>",s)}1' application.xml

How do we use a variable in the awk command?

Thanks in advance

This post should put you in the right direction:

http://www.unix.com/shell-programming-scripting/67986-replace-nth-value-xml-file.html\#post302202508

Regards