Advise how to swap node values for every occurrence?

Questions about XML that are not covered by the other forums should go here.
jcblitz
Posts: 2
Joined: Tue Sep 02, 2008 5:31 am

Advise how to swap node values for every occurrence?

Post by jcblitz »

Can anyone recommend a way to swap two node values for every occurrence of STMTTRN?

For instance:

Code: Select all

<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>123</DTPOSTED>
<DTUSER>456</DTUSER>
<TRNAMT>-30.00</TRNAMT>
<FITID>987654321</FITID>
<NAME>Value A</NAME>
<MEMO>Value B</MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>456</DTPOSTED>
<DTUSER>789</DTUSER>
<TRNAMT>-50.00</TRNAMT>
<FITID>1234567890</FITID>
<NAME>Value C</NAME>
<MEMO>Value D</MEMO>
</STMTTRN>
the nodes NAME and MEMO values flip, becoming

Code: Select all

<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>123</DTPOSTED>
<DTUSER>456</DTUSER>
<TRNAMT>-30.00</TRNAMT>
<FITID>987654321</FITID>
<NAME>Value B</NAME>
<MEMO>Value A</MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>456</DTPOSTED>
<DTUSER>789</DTUSER>
<TRNAMT>-50.00</TRNAMT>
<FITID>1234567890</FITID>
<NAME>Value D</NAME>
<MEMO>Value C</MEMO>
</STMTTRN>
I wanted to avoid writing a Java app to do something fairly trivial. Is there a way to do this just within Oxygen?
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Advise how to swap node values for every occurrence?

Post by sorin_ristache »

Hello,

I think it is easier with an XSLT stylesheet that transforms the first XML document to the second one. You can start from an identity transform (look for such a transform with Google) and add some XSLT templates to that until the stylesheet does your transformation. You apply the XSLT transform in Oxygen with a transformation scenario.


Regards,
Sorin
jcblitz
Posts: 2
Joined: Tue Sep 02, 2008 5:31 am

Re: Advise how to swap node values for every occurrence?

Post by jcblitz »

sorin wrote:Hello,

I think it is easier with an XSLT stylesheet that transforms the first XML document to the second one. You can start from an identity transform (look for such a transform with Google) and add some XSLT templates to that until the stylesheet does your transformation. You apply the XSLT transform in Oxygen with a transformation scenario.


Regards,
Sorin
Thanks, I'll look into it. My original thought was to use XSLT but then I figured since I'm really concerned with the xml data itself, not as a datasource, that might be the wrong route.
Post Reply