Creating new subtotal nodes grouped by 2 values

J

J. T.

I'm fairly new to XSL, but have made some good progress in picking it
up for the project I'm currently working on. I've been trying to
figure out how to design a stylesheet that would transform the XML I'm
recieving so that the tax information I'm recieving per item could be
grouped and added per state and have the new subtotal node located
inside the last node of a particular STORE value.

I'm trying to use the Muenchian Method, but I can't seem to wrap my
brain around it. The XML is already sorted by STORE, so I'm just
trying to figure out how to use Muenchian properly to get the desired
XML. I could really use some help in trying to figure out how to
group and subtotal the tax nodes and get the output I desire. Thanks
in advance.

Input:

<INV>
<PAGE num="1">
<STORE>1</STORE>
<ITEM>X</ITEM>
<TAX num="1">
<STATE>GA</STATE>
<TOTAL>10</TOTAL>
</TAX>
</PAGE>

<PAGE num="2">
<STORE>1</STORE>
<ITEM>Y</ITEM>
<TAX num="1">
<STATE>GA</STATE>
<TOTAL>5</TOTAL>
<TAX>
</TAX num="2">
<STATE>FL</STATE>
<TOTAL>5</TOTAL>
</TAX>
</PAGE>

<PAGE num="3">
<STORE>1</STORE>
<ITEM>Misc.</ITEM>
<TAX num="1">
<STATE>FL</STATE>
<TOTAL>5</TOTAL>
<TAX>
</TAX num="2">
<STATE>SC</STATE>
<TOTAL>5</TOTAL>
</TAX>
</PAGE>

<PAGE num="4">
<STORE>2</STORE>
<ITEM>Z</ITEM>
<TAX num="1">
<STATE>GA</STATE>
<TOTAL>0</TOTAL>
</TAX>
</PAGE>
</INV>

Desired Output:

<INV>
<PAGE num="1">
<STORE>1</STORE>
<ITEM>X</ITEM>
</PAGE>
<PAGE num="2">
<STORE>1</STORE>
<ITEM>Y</ITEM>
</PAGE>
<PAGE num="3">
<STORE>1</STORE>
<ITEM>Misc.</ITEM>
<TAX_SUBTOTAL>
<SUB_TAX num="1">
<SUB_STATE>GA</STATE>
<SUB_TOTAL>15</STATE>
</SUB_TAX>
<SUB_TAX num="2">
<SUB_STATE>SC</STATE>
<SUB_TOTAL>5</STATE>
</SUB_TAX>
<SUB_TAX num="3">
<SUB_STATE>FL</STATE>
<SUB_TOTAL>10</STATE>
</SUB_TAX>
<TAX_SUBTOTAL>
</PAGE>
<PAGE num="4">
<STORE>2</STORE>
<ITEM>Z</ITEM>
<TAX_SUBTOTAL>
<SUB_TAX num="2">
<SUB_STATE>GA</STATE>
<SUB_TOTAL>0</STATE>
</SUB_TAX>
<TAX_SUBTOTAL>
</PAGE>
</INV>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top