XML technologies / XSLT / XSLT 3.0 / XSLT streaming / Elements / xsl:merge / Merging employee lists

Exercise 7

Write an XSLT transformation that combines all employee data in XML format from the input folder (Flexus.xml, MatrixArchitecturalService.xml, MaxiTech.xml, Naugles.xml and Stratapro.xml). The people are already sorted alphabetically in each company directory. Apply the transformation to the XSLT file.

The output file should contain all employee data from all companies, sorted alphabetically, with first name, surname and company.

Code example: required output for exercise 7 (excerpt).

<Personenliste>
  ...
  <Person Firma="Matrix Architectural Service">
    <Vorname>Stefanie</Vorname>
    <Nachname>Aachen</Nachname>
  </Person>
  <Person Firma="Maxi-Tech">
    <Vorname>Kristin</Vorname>
    <Nachname>Abendroth</Nachname>
  </Person>
  ...
</Personenliste>

Excerpt from the merged employee list in the transformation result.

Use the transformation scenario [Übung 7] xsl:merge - Zusammenführen von Mitarbeiterlisten (n XML >> 1 XML) (see the notes on the exercises) and the following XSLT file:

Code example: stylesheet for exercise 7: merging employee lists.

<?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">
  <!-- Alle XML-Dateien aus Ordner auslesen: uri-collection('../in?select=*.xml')   
       Output-Vorlage:
       <Personenliste>
         <Person Firma="Maxi-Tech">
           <Vorname>Stefanie</Vorname>
           <Nachname>Aachen</Nachname>
         </Person>
       </Personenliste>
  -->
  <xsl:output indent="yes" />
  <xsl:strip-space elements="*" />
  <xsl:mode streamable="yes" on-no-match="shallow-copy" />
</xsl:stylesheet>

Tip

Reading all XML files in a folder

Using the function uri-collection('../in?select=*.xml') all XML files in the input folder can be read.

Extension

Disrupt the order in one of the input files and run the transformation again.

What happens? Why? How can this be fixed?

Solution

The complete output XML and the solution stylesheet can be found under Solutions to Exercise 7: merging employee lists.

   

back to top