XSLT grouping on multiple keys using Muenchian method

rockstarkidm

New Member
This is the input file.All these blocks are wrapped in a \[code\]<allocfile>\[/code\] tag which is not appearing, dunno why? And all these blocks are wrapped in a top level element \[code\]<xml>\[/code\].\[code\]<XML> <AllocFile> <alc>1</alc> <No>11/10</No> <DT>20090401</DT> <G_H>147</G_H> <FUN>125487</FUN> <oH>11</oH> <y>9</y> <AMOUNT>8000000</AMOUNT> <Code>033195</Code> <hd1>1234</hd1> </AllocFile> <AllocFile> <alc>2</alc> <No>14/10</No> <DT>20090401</DT> <G_H>147</G_H> <FUN>125487</FUN> <oH>11</oH> <y>9</y> <AMOUNT>8400000</AMOUNT> <Code>033195</Code> <hd1>1234</hd1> </AllocFile> <AllocFile> <alc>3</alc> <No>74/10</No> <DT>20090401</DT> <G_H>147</G_H> <FUN>125487</FUN> <oH>11</oH> <y>9</y> <AMOUNT>8740000</AMOUNT> <Code>033195</Code> <hd1>1234</hd1> </AllocFile> <AllocFile> <alc>2</alc> <No>74/10</No> <DT>20090401</DT> <G_H>117</G_H> <FUN>125487</FUN> <oH>19</oH> <y>9</y> <AMOUNT>74512</AMOUNT> <Code>033118</Code> <hd1>1234</hd1> </AllocFile> <AllocFile> <alc>3</alc> <No>14/10</No> <DT>20090401</DT> <G_H>117</G_H> <FUN>125487</FUN> <oH>19</oH> <y>9</y> <AMOUNT>986541</AMOUNT> <Code>033147</Code> <hd1>1234</hd1> </AllocFile> </XML>\[/code\]The output is \[code\]<Header1> <Hd1>1234</Hd1> <CodeHeader> <Code>033195</Code> <Header2> <G_H>147</G_H> <FUN>125487</FUN> <oH>11</oH> <y>9</y> <allocheader> <alc>1</alc> <No>11/10</No> <DT>20090401</DT> <AMOUNT>8000000</AMOUNT> </allocheader> <allocheader> <alc>2</alc> <No>14/10</No> <DT>20090401</DT> <AMOUNT>8400000</AMOUNT> </allocheader> <allocheader> <alc>3</alc> <No>74/10</No> <DT>20090401</DT> <AMOUNT>8740000</AMOUNT> </allocheader> </Header2> </CodeHeader> <CodeHeader> <Code>033118</Code> <Header2> <G_H>117</G_H> <FUN>125487</FUN> <oH>19</oH> <y>9</y> <allocheader> <alc>2</alc> <No>74/10</No> <DT>20090401</DT> <AMOUNT>74512</AMOUNT> </allocheader> </Header2> </codeHeader> <CodeHeader> <Code>033147</Code> <Header2> <G_H>117</G_H> <FUN>125487</FUN> <oH>19</oH> <y>9</y> <allocheader> <alc>3</alc> <No>14/10</No> <DT>20090401</DT> <AMOUNT>986541</AMOUNT> </allocheader> </Header2> </CodeHeader></Header1>\[/code\]The input file needs to be sorted and grouped on the basis of multiple keys. I proceeded using the \[code\]concat\[/code\] function and the Muenchian method but didn't much help from the web. I am using XSLT 1.0.Rules for Grouping
  • All the nodes in the file will have \[code\]<hd1>\[/code\] with values \[code\]1234..\[/code\] this becomes the first group by key and appears in the output as \[code\]<Header1>\[/code\]
    • the second key for grouping is the node code . nodes having same value get grouped together. appears as. code header
  • The second key is the group of nodes \[code\]G_H\[/code\], \[code\]FUN\[/code\], \[code\]oH\[/code\], \[code\]y\[/code\]. If all these have the same values for nodes, they get grouped together. It appears in the output as \[code\]<Header2>\[/code\]
  • No grouping happens on the nodes \[code\]<alc>\[/code\], \[code\]<No>\[/code\], \[code\]<DT>\[/code\], \[code\]<AMOUNT>\[/code\]. They have distinct values within each group.
 
Back
Top