XML technologies / XSLT / XSLT 3.0 / XSLT streaming / Elements / xsl:fork / Splitting an employee list
Exercise 11
As an exercise, an XML file containing an employee list should be split into two separate XML files: one listing all men and the other all women. Use the xsl:fork instruction to distribute the processing across multiple processes.
To do this, select one of the files (Flexus.xml, MatrixArchitecturalService.xml, Maxi-Tech.xml, Naugles.xml or Stratapro.xml) from the in folder.
Code example: required output – women (excerpt).
<Company Name="Flexus">
<Person>
<Name Title="Ms." Gender="female">
<Firstname>Laura</Firstname>
<Surname>Ackermann</Surname>
</Name>
<Birthday>2/21/1963</Birthday>
...
</Person>
<Person>
<Name Title="Ms." Gender="female">
<Firstname>Lena</Firstname>
<Surname>Bar</Surname>
</Name>
<Birthday>1/29/1973</Birthday>
...
</Person>
<Person>
<Name Title="Mrs." Gender="female">
<Firstname>Jennifer</Firstname>
<Surname>Bayer</Surname>
</Name>
<Birthday>6/21/1953</Birthday>
...
</Person>
...
</Company>Output of the women.
Use the transformation scenario [Übung 11] xsl:fork - Personenliste (1 XML >> 2 XML) (see the notes on the exercises) and the following XSLT file:
Code example: stylesheet for exercise 11: splitting an employee list.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0">
<!-- AUFGABE: Schreiben Sie eine XSLT-Transformation, um eine Personen-Liste in zwei XML-Dateien aufzuteilen. In einer Datei sollen alle männlichen Personen und in der anderen alle weiblichen enthalten sein. -->
<!-- AUSGABE:
female.xml:
<Females>
<Name Title="Ms." Gender="female">
<Firstname>Laura</Firstname>
<Surname>Ackermann</Surname>
</Name>
<Name Title="Ms." Gender="female">
<Firstname>Lena</Firstname>
<Surname>Bar</Surname>
</Name>
</Females>
male.xml
<Males>
<Name Title="Mr." Gender="male">
<Firstname>René</Firstname>
<Surname>Beckenbauer</Surname>
</Name>
<Name Title="Mr." Gender="male">
<Firstname>Benjamin</Firstname>
<Surname>Biermann</Surname>
</Name>
</Males>
-->
<xsl:output indent="yes"/>
<xsl:mode streamable="yes"/>
<xsl:template match="Company">
<xsl:fork> </xsl:fork>
</xsl:template>
</xsl:stylesheet>Extension
Try to solve the task without xsl:fork. What do you notice?
Tip
Creating an additional output file
Using xsl:result-document you can create an additional output file. Its name is specified in the href attribute.
Solution
The complete output XML and the solution stylesheet can be found under Solutions to Exercise 11: splitting an employee list.