Lösungen zu Übung 8: Gelbe Seiten (xsl:merge)

Im Folgenden finden Sie die Lösungsdateien zu Übung 8 unter Gelbe Seiten.

Code-Beispiel: Lösungs-XSLT zu Übung 8.

<?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">
  <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>
            <xsl:merge>
              <xsl:merge-source for-each-stream="uri-collection('../in?select=*.xml')" streamable="yes" select="osm/node">
                <xsl:merge-key select="spieltHierKeineRolle" />
              </xsl:merge-source>
              <xsl:merge-action>
                <xsl:apply-templates select="current-merge-group()" mode="no-Streaming" />
              </xsl:merge-action>
            </xsl:merge>
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="node[tag/@k = 'shop']" mode="no-Streaming">
    <tr>
      <td>
        <xsl:apply-templates select="tag[@k = 'shop']" mode="#current" />
      </td>
      <td>
        <xsl:apply-templates select="tag[@k = 'name']" mode="#current" />
      </td>
      <td>
        <xsl:apply-templates select="tag[@k = 'addr:street']" mode="#current" />
        <xsl:apply-templates select="tag[@k = 'addr:housenumber']" mode="#current" />
        <xsl:apply-templates select="tag[@k = 'addr:postcode']" mode="#current" />
        <xsl:apply-templates select="tag[@k = 'addr:city']" mode="#current" />
      </td>
      <td>
        <xsl:apply-templates select="tag[@k = 'contact:phone']" mode="#current" />
      </td>
      <td>
        <xsl:apply-templates select="tag[@k = 'website']" mode="#current" />
      </td>
    </tr>
  </xsl:template>
  <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>

Anmerkung der data2type-Redaktion:
Da das folgende Code-Beispiel den Rahmen sprengen würde (ca. 9000 Zeilen Code), folgt hier nur ein Auszug aus der Lösungs-HTML-Datei.

Code-Beispiel: Output-HTML zu Übung 8 (Auszug).

<?xml version="1.0" encoding="UTF-8"?>
<html>
  <head>
    <title>Gelbe Seiten</title>
    <link rel="stylesheet" type="text/css" href="../styling/dataTables/bootstrap.min.css"></link>
    <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.bootstrap.css"></link>
    <link rel="stylesheet" type="text/css" href="../styling/dataTables/dataTables.colVis.css"></link>
    <link rel="stylesheet" type="text/css" href="../styling/styles.css"></link>
    <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>gift</td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>books</td>
          <td>Berlin Story</td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>kiosk</td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>mall</td>
          <td>Galeries Lafayette</td>
          <td>Friedrichstraße 76-78, 10117 Berlin </td>
          <td></td>
          <td><a href="http://www.galerieslafayette.de/">Website</a></td>
        </tr>
        <tr>
          <td>rc_models</td>
          <td>Staufenbiel</td>
          <td></td>
          <td></td>
          <td><a href="modellhobby.de">Website</a></td>
        </tr>
        <tr>
          <td>massage</td>
          <td>Wang Spa</td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>supermarket</td>
          <td>Edeka</td>
          <td>Friedrichstraße 142, 10117 Berlin </td>
          <td></td>
          <td><a href="http://www.edeka-bahnhof.de">Website</a></td>
        </tr>
        <tr>
          <td>car</td>
          <td>Automobil Forum</td>
          <td>Friedrichstraße 84, 10117 Berlin </td>
          <td></td>
          <td><a href="http://www.volkswagenag.com/content/afb/content/de/homepage.html">Website</a></td>
        </tr>
        <tr>
          <td>confectionery</td>
          <td>Bunte Schokowelt</td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>confectionery</td>
          <td>Fassbender &amp; Rausch Chocolatiers am Gendarmenmarkt</td>
          <td>Charlottenstraße 60, 10117 Berlin </td>
          <td></td>
          <td><a href="http://www.fassbender-rausch.de">Website</a></td>
        </tr>
        ...
      </tbody>
    </table>
  </body>
</html>
           
Tipp der data2type-Redaktion:
Zum Thema XSLT bieten wir auch folgende Schulungen zur Vertiefung und professionellen Fortbildung an: