XML technologies / XSLT / XSLT 3.0 / XSLT streaming / Elements / xsl:merge / Yellow pages

Exercise 8

Write an XSLT transformation that combines all OpenStreetMap data from the input folder (Berlin_Ausschnitt.xml, Muenchen_Ausschnitt.xml and Stuttgart_Mitte.xml). The result should be an HTML page with a combined table of all shops from all cities. Apply the transformation to the XSLT file.

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

<table id="liste" class="table table-striped table-hover">
  <thead>
    <tr>
      <th>Typ</th>
      <th>Shop</th>
      <th>Adresse</th>
      <th>Telefon</th>
      <th>Website</th>
    </tr>
  </thead>
  <tbody>
    ...
    <tr>
      <td>bakery</td>
      <td>H&amp;F Bäckerei</td>
      <td>Friedrichstraße 9A, 70174 Stuttgart</td>
      <td>+49 711 3007409</td>
      <td><a href="http://www.hf-baeckerei.de/">Website</a></td>
    </tr>
    ...
  </tbody>
</table>

Excerpt from the HTML table in the transformation result.

Copy the listed JavaScript and CSS includes around the table into the head of the HTML file to make the HTML table searchable.

Code example: styling.

<link rel="stylesheet" href="../styling/dataTables/bootstrap.min.css" />
<link rel="stylesheet" href="../styling/dataTables/dataTables.bootstrap.css" />
<link rel="stylesheet" href="../styling/dataTables/dataTables.colVis.css" />
<link rel="stylesheet" href="../styling/styles.css" />
<script src="../styling/dataTables/jquery-1.11.1.min.js"></script>
<script src="../styling/dataTables/jquery.dataTables.min.js"></script>
<script src="../styling/dataTables/dataTables.bootstrap.js"></script>
<script src="../styling/dataTables/dataTables.colVis.js"></script>
<script src="../styling/dataTables/dataTables.fixedHeader.js"></script>
<script src="../styling/script.js"></script>

Use the transformation scenario [Übung 8] xsl:merge - Gelbe Seiten (n XML >> 1 HTML) (see the notes on the exercises) and the following XSLT file:

Code example: stylesheet for exercise 8: yellow pages.

<?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">
  <!-- Output-Vorlage:
    <html>
      <head>
        <title>Gelbe Seiten</title>
        <meta charset="utf-8"/>
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.colVis.css" />
        <link rel="stylesheet" type="text/css" href="../styling/styles.css" />
        <script type="text/javascript" src="../styling/dataTables/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../styling/dataTables/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="../styling/dataTables/dataTables.bootstrap.js"></script>
        <script type="text/javascript" src="../styling/dataTables/dataTables.colVis.js"></script>
        <script type="text/javascript" src="../styling/dataTables/dataTables.fixedHeader.js"></script>
        <script type="text/javascript" src="../styling/script.js"></script>
      </head>
      <body>
        <h1>Gelbe Seiten</h1>
        <table id="liste" class="table table-striped table-hover">
          <thead>
            <tr>
              <th>Typ</th>
              <th>Shop</th>
              <th>Adresse</th>
              <th>Telefon</th>
              <th>Website</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>garden_centre</td>
              <td>Dehner Zoo</td>
              <td>Reichenbachstraße 3, 80469 München </td>
              <td></td>
              <td><a href="http://www.dehner.de/">Website</a></td>
            </tr>
          </tbody>
        </table>
      </body>
    </html>    
  -->
  <xsl:output indent="yes" method="xhtml" />
  <xsl:mode streamable="yes" />
  <xsl:mode streamable="no" name="no-Streaming" />
  <xsl:template match="/">
    <html>
      <head>
        <title>Gelbe Seiten</title>
        <meta charset="utf-8"/>
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.colVis.css" />
        <link rel="stylesheet" type="text/css" href="../styling/styles.css" />
        <script type="text/javascript" src="../styling/dataTables/jquery-1.11.1.min.js" />
        <script type="text/javascript" src="../styling/dataTables/jquery.dataTables.min.js" />
        <script type="text/javascript" src="../styling/dataTables/dataTables.bootstrap.js" />
        <script type="text/javascript" src="../styling/dataTables/dataTables.colVis.js" />
        <script type="text/javascript" src="../styling/dataTables/dataTables.fixedHeader.js" />
        <script type="text/javascript" src="../styling/script.js" />
      </head>
      <body>
        <h1>Gelbe Seiten</h1>
        <table id="liste" class="table table-striped table-hover">
          <thead>
            <tr>
              <th>Typ</th>
              <th>Shop</th>
              <th>Adresse</th>
              <th>Telefon</th>
              <th>Website</th>
            </tr>
          </thead>
          <tbody>
            <!-- HIER XML-DATEIEN MERGEN -->
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>
  <!-- HIER TABELLEN-ZEILE ERSTELLEN (mode="no-Streaming") -->
  <!-- die restlichen HTML-Elemente erstellen -->
  <xsl:template match="node[not(tag/@k = 'shop')]" mode="no-Streaming" />
  <xsl:template match="tag[matches(@k, '(name|contact:phone|opening_hours|shop)')]" mode="no-Streaming">
    <xsl:value-of select="@v" />
  </xsl:template>
  <xsl:template match="tag[matches(@k, 'addr:(street|postcode|city)')]" mode="no-Streaming">
    <xsl:value-of select="@v" />
    <xsl:text> </xsl:text>
  </xsl:template>
  <xsl:template match="tag[matches(@k, 'addr:(housenumber)')]" mode="no-Streaming">
    <xsl:value-of select="@v" />
    <xsl:text>, </xsl:text>
  </xsl:template>
  <xsl:template match="tag[matches(@k, '(website)')]" mode="no-Streaming">
    <a href="{@v}">Website</a>
  </xsl:template>
</xsl:stylesheet>

Tips

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.

Bypassing sorting

The individual files are not presorted. Since they are to be streamed, sorting can be bypassed by specifying any element or attribute (<xsl:merge-key select="spieltHierKeineRolle"/>).

Solution

The complete output HTML and the solution stylesheet can be found under Solutions to Exercise 8: Yellow Pages.

   

back to top