XML variable for input in same input file

Dear All ,

i stuck in one problem executing xml .. i have input xml as

   <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial">
        <SVLOBJECT>
            <LONG name="CSP_PMNT_ID" val="-1"/>
            <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/>
            <DATE name="CSP_VALID_FROM" year="2013" month="12" day="3"/>
        </SVLOBJECT>
        <RESULT>
            <SVLOBJECT>
                <LONG name="CSP_ID" val="2043"/>
            </SVLOBJECT>
        </RESULT>
    </COMMAND>
    <COMMAND name="ARRANGEMENT_ASSIGNMENT.WRITE" timestamp="0" so="initial">
        <SVLOBJECT>
            <LONG name="PAYMENT_ID" val="2043"/> -- 
            <LONG name="TERM_CODE" val="2"/>
            <DATE name="VALID_FROM" year="2013" month="12" day="3"/>
        </SVLOBJECT>
        <RESULT>
            <SVLOBJECT>
                <LONG name="PAY_ARR_ID" val="2043"/>
            </SVLOBJECT>
        </RESULT>
    </COMMAND>

now here in result of first command coming as name="CSP_ID" val="2043
and i want to use this in value in next command .. can anyone help on this ..

thanks in Advance !!!

Not clear what you want to achieve. Please be way more specific!

Assuming you want to extract the value and use it later:

csp_id_val=$( awk '/CSP_ID/{gsub(/.*=\"|".*/,X);print;exit}' file.xml )
$ csp_id_val=$(grep -Po -m1 '(?<="CSP_ID" val=").*(?=\"/>)' file)
$ echo $csp_id_val
2043

Yoda, can you explain the | in your command gsub please.
Thx.

It's like an "OR" in regexes; so either part when matching is replaced by the empty variable X.

ok it's clear, thx.