Tecnologías XML / XSLT / XSLT 3.0 / Streaming XSLT / Elementos / xsl:merge / Páginas amarillas
Ejercicio 8
Escriba una transformación XSLT que combine todos los datos de OpenStreetMap procedentes de la carpeta de entrada (Berlin_Ausschnitt.xml, Muenchen_Ausschnitt.xml y Stuttgart_Mitte.xml). El resultado debe ser una página HTML con una tabla conjunta de todos los comercios de todas las ciudades. Aplique la transformación al archivo XSLT.
Ejemplo de código: salida requerida para el ejercicio 8 (extracto).
<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>Extracto de la tabla HTML en el resultado de la transformación.
Copie las referencias JavaScript y CSS que rodean la tabla en la sección head del archivo HTML para permitir búsquedas en la tabla HTML.
Ejemplo de código: estilos.
<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>Utilice el escenario de transformación [Übung 8] xsl:merge - Gelbe Seiten (n XML >> 1 HTML) (véanse las explicaciones de los ejercicios) y el siguiente archivo XSLT:
Ejemplo de código: hoja de estilo para el ejercicio 8: páginas amarillas.
<?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>
Consejos
Leer todos los archivos XML de una carpeta
Mediante la función uri-collection('../in?select=*.xml') pueden leerse todos los archivos XML de la carpeta de entrada.
Evitar la ordenación
Los archivos no están ordenados previamente. Como deben procesarse en streaming, puede evitarse la ordenación indicando cualquier elemento o atributo (<xsl:merge-key select="spieltHierKeineRolle"/>).
Solución
El HTML de salida completo y la hoja de estilo de solución se encuentran en Soluciones del ejercicio 8: Páginas Amarillas.