Here we are going to discus about how to group the tags under some condition in xslt. I will explain this by taking the Employer example.
Before this we need to know some of the xslt functions and template calling .
<?xml version="1.0" ?>
To do this
Before this we need to know some of the xslt functions and template calling .
- generate-id()
- key()
- <xsl:key>
- <xsl:template>
<?xml version="1.0" ?>
<Employees>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>1</TaskID>
<Hours>5</Hours>
<EmployeeID>1</EmployeeID>
<Name>Bob</Name>
<Surname>Shibob</Surname>
</Employee>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>2</TaskID>
<Hours>4</Hours>
<EmployeeID>1</EmployeeID>
<Name>Bob</Name>
<Surname>Shibob</Surname>
</Employee>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>4</TaskID>
<Hours>7</Hours>
<EmployeeID>2</EmployeeID>
<Name>Sara</Name>
<Surname>Lee</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>5</TaskID>
<Hours>2</Hours>
<EmployeeID>3</EmployeeID>
<Name>John</Name>
<Surname>Smith</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>3</TaskID>
<Hours>4</Hours>
<EmployeeID>4</EmployeeID>
<Name>Penny</Name>
<Surname>Wise</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>5</TaskID>
<Hours>3</Hours>
<EmployeeID>4</EmployeeID>
<Name>Penny</Name>
<Surname>Wise</Surname>
</Employee>
</Employees>
· First declare the one key variable
<xsl:key name=" keyEmployeeID" match="Employee" use=" EmployeeID"/>
· Then write a for loop for iterating the Employee set
<xsl:for-each select="Employee”>
· Then generate and id for each key value of employes
<xsl:for-each select="…………generate-id(key('keyEmployeeID', EmployeeID)[1])]">
· Assign all this ids in to a array
<xsl:for-each select="tEmployee[generate-id(.) = generate-id(key('keyEmployeeID', EmployeeID)[1])]">