I am trying to convert a nested XML structure to a Flat XML using for-each in xslt but struggling :( Below is my source and target, so any inputs using XSLT will be very appreciated.
Source XML
<dlu fD="2012-06-07" tD="2012-06-13"> <ULUI uid="uid-1" fAD="2012-06-11" lAD="2012-06-11"> <LU license="License1" count="1"/> </ULUI> <ULUI uid="uid-2" fAD="2012-06-10" lAD="2012-06-10"> <LU license="License1" count="1"/> </ULUI> <ULUI uid="uid-3" fAD="2012-06-09" lAD="2012-06-09"> <LU license="License1" count="1"/> </ULUI> <ULUI uid="uid-4" fAD="2012-06-07" lAD="2012-06-08"> <LU license="License3" count="1"/> <LU license="License4" count="1"/> </ULUI> <ULUI uid="uid-5" fAD="2012-06-07" lAD="2012-06-08"> <LU license="License1" count="1"/> <LU license="License5" count="1"/> </ULUI> </dlu> <dlu fD="2012-06-14" tD="2012-06-20"> <ULUI uid="uid-1" fAD="2012-06-14" lAD="2012-06-14"> <LU license="License1" count="1"/> </ULUI> <ULUI uid="uid-2" fAD="2012-06-15" lAD="2012-06-20"> <LU license="License2" count="1"/> <LU license="License4" count="1"/> </ULUI> <ULUI uid="uid-3" fAD="2012-06-16" lAD="2012-06-19"> <LU license="License1" count="1"/> <LU license="License5" count="1"/> </ULUI> <ULUI uid="uid-4" fAD="2012-06-17" lAD="2012-06-18"> <LU license="License1" count="1"/> <LU license="License3" count="1"/> </ULUI> <ULUI uid="uid-5" fAD="2012-06-17" lAD="2012-06-18"> <LU license="License7" count="1"/> <LU license="License9" count="1"/> </ULUI> </dlu>
Target XML
<FDLU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-1</LU_UID> <LU_FA_DT>2012-06-11</LU_FA_DT> <LU_LA_DT>2012-06-11</LU_LA_DT> <LU_LICENSE>License1</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-2</LU_UID> <LU_FA_DT>2012-06-10</LU_FA_DT> <LU_LA_DT>2012-06-10</LU_LA_DT> <LU_LICENSE>License1</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-4</LU_UID> <LU_FA_DT>2012-06-07</LU_FA_DT> <LU_LA_DT>2012-06-08</LU_LA_DT> <LU_LICENSE>License3</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-4</LU_UID> <LU_FA_DT>2012-06-07</LU_FA_DT> <LU_LA_DT>2012-06-08</LU_LA_DT> <LU_LICENSE>License4</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-5</LU_UID> <LU_FA_DT>2012-06-07</LU_FA_DT> <LU_LA_DT>2012-06-08</LU_LA_DT> <LU_LICENSE>License1</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LU> <LD_FR_DT>2012-06-07</LD_FR_DT <LD_TO_DT>2012-06-13</LD_TO_DT> <LU_UID>uid-5</LU_UID> <LU_FA_DT>2012-06-07</LU_FA_DT> <LU_LA_DT>2012-06-08</LU_LA_DT> <LU_LICENSE>License5</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> <LD_FR_DT>2012-06-14</LD_FR_DT <LD_TO_DT>2012-06-20</LD_TO_DT> <LU_UID>uid-1</LU_UID> <LU_FA_DT>2012-06-14</LU_FA_DT> <LU_LA_DT>2012-06-14</LU_LA_DT> <LU_LICENSE>License1</LU_LICENSE> <LU_COUNT>1</LU_COUNT> </LU> ..... </FDLU>
So basically I need a flat row per LU from source, but my ULUI & DLU are also unbounded so they can appear more than once. I am looking for a solution in xslt 1.0 or 2.0 version. I started with for-each LU and then tried to proceed, but I'm not able to handle ULUI and DLU multi occurrence and values for them simply end up in one line.
No comments:
Post a Comment