Technologies XML / XSLT / XSLT 3.0 / Streaming XSLT / Éléments / xsl:merge / Pages jaunes
Exercice 8
Écrivez une transformation XSLT qui fusionne les données d’OpenStreetMap provenant du dossier d’entrée (Berlin_Ausschnitt.xml, Muenchen_Ausschnitt.xml et Stuttgart_Mitte.xml). Le résultat doit être une page HTML contenant un tableau commun de tous les commerces de toutes les villes. Appliquez la transformation au fichier XSLT.
Exemple de code : sortie attendue pour l’exercice 8 (extrait).
<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&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>Extrait du tableau HTML dans le résultat de la transformation.
Copiez les inclusions JavaScript et CSS qui entourent le tableau dans la section head du fichier HTML pour permettre la recherche dans le tableau HTML.
Exemple de code : styles.
<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>Utilisez le scénario de transformation [Übung 8] xsl:merge - Gelbe Seiten (n XML >> 1 HTML) (voir les explications des exercices) et le fichier XSLT suivant :
Exemple de code : feuille de style pour l’exercice 8 : pages jaunes.
<?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>
Conseils
Lire tous les fichiers XML d’un dossier
À l’aide de la fonction uri-collection('../in?select=*.xml') tous les fichiers XML du dossier d’entrée peuvent être lus.
Contourner le tri
Les fichiers ne sont pas prétriés. Comme ils doivent être traités en streaming, on peut contourner le tri en indiquant un élément ou un attribut quelconque (<xsl:merge-key select="spieltHierKeineRolle"/>).
Solution
Le HTML de sortie complet et la feuille de style de solution se trouvent sous Solutions de l’exercice 8 : Pages Jaunes.