Schritt 4 - eine XSL-Datei

Mit der XSL-Datei wird festgelegt, wie die Inhalte des XML-Dokuments dargestellt werden sollen.

Diese XSL-Datei ist für den Internet Explorer 5 spezialisiert (die W3C konforme Variante)

Beispiel 4-1
<?xml version="1.0"?>
<xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/TR/WD-xsl" 
   xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional">



<!-- =============================== -->
<!-- Wenn Wurzelelement aktiv ist    --> 
<!-- erstelle HTML-Grundgeruest      -->
<!-- =============================== -->

<xsl:template match="/">
<html>
<head>
   <title>Anzeige des Dokuments schritt-2.xml</title>
</head>
<body>
   <xsl:apply-templates/>
</body>
</html>
</xsl:template>


<!-- ===============================      -->
<!-- PRODUKTE sorgt fuer Tabelle komplett -->
<!-- ===============================      -->

<xsl:template match="PRODUKTE">
   <table border="1">
      <xsl:apply-templates/>
   </table>
</xsl:template>


<!-- ===============================           -->
<!-- Ein PRODUKT wird in einer Zeile angezeigt -->
<!-- ===============================           -->

<xsl:template match="PRODUKT">
      <tr>
         <xsl:apply-templates/>
      </tr>
</xsl:template>


<!-- ===============================                -->
<!-- zeige diese Elemente jeweils in einer Zelle an -->
<!-- ===============================                -->

<xsl:template match="NAME|HERSTELLER|PREIS">
         <td>
            <xsl:apply-templates/>
         </td>
</xsl:template>


<!-- ===============================                   -->
<!-- hier wird der Textinhalt aller Element ausgegeben -->
<!-- ===============================                   -->


<xsl:template match="text()">
             <xsl:value-of select="."/>
</xsl:template>


</xsl:stylesheet>

In das XML-Dokument des Schritts 1 wird eine Zeile eingefügt, die die XSL-Datei benennt (hier "schritt-2.xsl", also im selben Verzeichnis wie das XML-Dokument).

Beispiel 4-2
<?xml:stylesheet type="text/xsl" href="xml-schritt-4.xsl"?>

 

Beispiel 4-3
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="xml-schritt-4.xsl"?>
<PRODUKTE> 
  <PRODUKT> 
    <NAME>Crugar</NAME> 
    <HERSTELLER>Ford</HERSTELLER> 
    <PREIS>34800</PREIS> 
  </PRODUKT>
  <PRODUKT>
    <NAME>Polo</NAME>
    <HERSTELLER>Volkswagen</HERSTELLER>
    <PREIS>28769</PREIS>
  </PRODUKT>
  <PRODUKT>
    <NAME>Astra</NAME>
    <HERSTELLER>Opel</HERSTELLER>
    <PREIS>31921</PREIS>
  </PRODUKT>
</PRODUKTE>

Das Dokument mit Verwendung der XSL-Datei (im Internet Explorer 5): xsl-schritt-4.xml

Die XSL-Datei zum direkten Anzeigen im Internet Explorer 5: xml-schritt-4.xsl

Alternativ hier ein Screenshot: xml-schritt-4.gif

Die XSL-Datei in der W3C-Variante:xml-schritt-4-w3c.xsl

Zurück