XSL to select and group distinct data based on 3 different parameters



I'm using XSL 1.0 and Xpath 1.0.


I'm new to XSL and XPath and there is this thing I'm trying to do in XSL using Oracle JDeveloper. I am selecting data from a table based on combination of 3 things that are "forename(mandatory), surname(can be null), and emp_type(can be null)". The query I used to retrieve data from table selects data for the provided "forename, surname(can be null) and emp_type(can be null)" and for the forename "Nina". "Nina" doesn't have a surname in the table as it is required to be retrieved by default however it may or may not have an "emp_type" What I want is to group data into distinct blocks with data for one particular combination of "forename, surname and emp_type" coming under one node of result after applying transformation. The data collection from table looks like the data below:


Data coming from table:



<OutputCollection>

<Output>

<forename>Anna</forename>

<surname>Collins</surname>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description1</descname>

<desc>Description</desc>

<comment>comment1</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname>Collins</surname>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description2</descname>

<desc>Description</desc>

<comment>comment2</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname>Collins</surname>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description3</descname>

<desc>Description</desc>

<comment>comment3</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description4</descname>

<desc>Description</desc>

<comment>comment4</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description5</descname>

<desc>Description</desc>

<comment>comment5</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description6</descname>

<desc>Description</desc>

<comment>comment6</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description7</descname>

<desc>Description</desc>

<comment>comment7</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description8</descname>

<desc>Description</desc>

<comment>comment8</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description9</descname>

<desc>Description</desc>

<comment>comment9</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description10</descname>

<desc>Description</desc>

<comment>comment10</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description11</descname>

<desc>Description</desc>

<comment>comment11</comment>

</Output>

<Output>

<forename>Anna</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description12</descname>

<desc>Description</desc>

<comment>comment12</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description13</descname>

<desc>Description</desc>

<comment>comment13</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description14</descname>

<desc>Description</desc>

<comment>comment14</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description15</descname>

<desc>Description</desc>

<comment>comment15</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description</descname>

<desc>Description16</desc>

<comment>comment16</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description18</descname>

<desc>Description</desc>

<comment>comment18</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description19</descname>

<desc>Description</desc>

<comment>comment19</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description20</descname>

<desc>Description</desc>

<comment>comment20</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description21</descname>

<desc>Description</desc>

<comment>comment21</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type>Permanent</emp_type>

<off_type>PERM</off_type>

<descname>Description22</descname>

<desc>Description</desc>

<comment>comment22</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description23</descname>

<desc>Description</desc>

<comment>comment23</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description24</descname>

<desc>Description</desc>

<comment>comment24</comment>

</Output>

<Output>

<forename>Nina</forename>

<surname nil="true"/>

<emp_type nil="true"/>

<off_type nil="true"/>

<descname>Description25</descname>

<desc>Description</desc>

<comment>comment25</comment>

</Output>

</OutputCollection>


Requirement:



<Response_After_Applying_Transformation>

<Outputs>

<Output>

<forename>Anna</forename>
<surname>Collins</surname>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>

<desc_groups>
<desc_group>
<descname>Description1</descname>
<desc>Description</desc>
<comment>comment1</comment>
</desc_group>
<desc_group>
<descname>Description2</descname>
<desc>Description</desc>
<comment>comment2</comment>
</desc_group>
<desc_group>
<descname>Description3</descname>
<desc>Description</desc>
<comment>comment3</comment>
</desc_group>
</desc_groups>
.
.
.

</Output>

<Output>

<forename>Anna</forename>
<surname/>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>

<desc_groups>
<desc_group>
<descname>Description4</descname>
<desc>Description</desc>
<comment>comment4</comment>
</desc_group>
<desc_group>
<descname>Description5</descname>
<desc>Description</desc>
<comment>comment5</comment>
</desc_group>
<desc_group>
<descname>Description6</descname>
<desc>Description</desc>
<comment>comment6</comment>
</desc_group>
</desc_groups>
.
.
.


</Output>

<Output>

<forename>Anna</forename>
<surname/>
<emp_type/>
<off_type/>

<desc_groups>
<desc_group>
<descname>Description10</descname>
<desc>Description</desc>
<comment>comment10</comment>
</desc_group>
<desc_group>
<descname>Description11</descname>
<desc>Description</desc>
<comment>comment11</comment>
</desc_group>
<desc_group>
<descname>Description12</descname>
<desc>Description</desc>
<comment>comment12</comment>
</desc_group>
</desc_groups>
.
.
.

</Output>

<Output>

<forename>Nina</forename>
<surname/>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>

<desc_groups>
<desc_group>
<descname>Description13</descname>
<desc>Description</desc>
<comment>comment13</comment>
</desc_group>
<desc_group>
<descname>Description14</descname>
<desc>Description</desc>
<comment>comment14</comment>
</desc_group>
<desc_group>
<descname>Description15</descname>
<desc>Description</desc>
<comment>comment15</comment>
</desc_group>
</desc_groups>
.
.
.

</Output>

<Output>

<forename>Nina</forename>
<surname/>
<emp_type/>
<off_type/>

<desc_groups>
<desc_group>
<descname>Description23</descname>
<desc>Description</desc>
<comment>comment23</comment>
</desc_group>
<desc_group>
<descname>Description24</descname>
<desc>Description</desc>
<comment>comment24</comment>
</desc_group>
<desc_group>
<descname>Description25</descname>
<desc>Description</desc>
<comment>comment25</comment>
</desc_group>
</desc_groups>
.
.
.

</Output>

</Outputs>

</Response_After_Applying_Transformation>


In case all this is not possible with a single transformation please help me with a way to find out distinct combinations of "forename, surname and emp_type" so that I can use it in another transformation to get the required result.


Required Intermediate Response:



<Intermediate_Response>

<Intermediate_Result>
<forename>Anna</forename>
<surname>Collins</surname>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>
</Intermediate_Result>

<Intermediate_Result>
<forename>Anna</forename>
<surname/>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>
</Intermediate_Result>

<Intermediate_Result>
<forename>Anna</forename>
<surname/>
<emp_type/>
<off_type/>
</Intermediate_Result>

<Intermediate_Result>
<forename>Nina</forename>
<surname/>
<emp_type>Permanent</emp_type>
<off_type>PERM</off_type>
</Intermediate_Result>

<Intermediate_Result>
<forename>Nina</forename>
<surname/>
<emp_type/>
<off_type/>
</Intermediate_Result>

</Intermediate_Response>


Your help will be deeply appreciated. I'll be really grateful to you all.


No comments:

Post a Comment