Announcement

Collapse
No announcement yet.

xslt funktioniert nicht

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • xslt funktioniert nicht

    Hallo,

    ich habe ein Problem. Die beiden unten stehenden xslt-Dateien funktionieren leider nicht. Bei der ersten zeigt er nur die Überschrift an, bei der zweiten gar nichts. Kann mir vielleicht jemand helfen? Ich finde die Fehler einfach nicht.


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="C:\Users\Kroete\Documents\Studium\8. Semester\XML\Pruefung\XSLT\Visitenkarte.xslt"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head>
    <title>Visitenkarte vom Arzt</title>
    </head>
    <body>
    <h1>Visitenkarte</h1>
    <table cellpadding="20" cellspacing="20">
    <xsl:for-each select="//Mitarbeiter_ID[ID_M1]">
    <tr>
    <td bgcolor="red">
    <b>
    <xsl:value-of select="Mitarbeiter/Nachname"/>
    </b>
    <b>
    <xsl:value-of select="Mitarbeiter/Vorname"/>
    </b>
    <br/>
    <i>
    <xsl:value-of select="Mitarbeiter/Telefonnummer"/>
    </i>
    <br/>
    <i>
    <xsl:value-of select="Mitarbeiter/Email"/>
    </i>
    <br/>
    <hr/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>



    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="C:\Users\Kroete\Documents\Studium\8. Semester\XML\Pruefung\XSLT\Geburtstag.xslt"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head><title>Geburtstag aller Patienten</title></head>
    <body>
    <h1>Geburtstag aller Patienten</h1>
    <table border="1">
    <tr bgcolor="green">
    <td><b><font size="4">Nachname</font></b></td>
    <td><b><font size="4">Vorname</font></b></td>
    <td><b><font size="4">Geburtsdatum</font></b></td>
    </tr>
    <xsl:apply-templates select="//Patienten">
    <xsl:sort select="Nachname"/>
    <xsl:sort select="Vorname"/>
    </xsl:apply-templates>
    </table>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="//Patienten">
    <tr>
    <td><xsl:value-of select="Nachname"></xsl:value-of></td>
    <td><xsl:value-of select="Vorname"></xsl:value-of></td>
    <td><xsl:value-of select="Geburtsdatum"></xsl:value-of></td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>

  • #2
    z

    dein ansatz ist falsch

    wie sieht die ursprung xml aus
    und bitte das gatter code benutzen

    Comment


    • #3
      xml bedeutet daten im container
      durch angabe am anfang der Datei können veränderungen
      vorgenommen werden
      beispiel

      xml
      Code:
      <?xml version="1.0"?>
      <Patientenkartei>
      	<Patient>
      		<Nachname>AAA</Nachname>
      		<Vorname>A1</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>BBB</Nachname>
      		<Vorname>B2</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>CCC</Nachname>
      		<Vorname>C3</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>DDD</Nachname>
      		<Vorname>D4</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>EEE</Nachname>
      		<Vorname>E5</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      </Patientenkartei>

      xsl datei
      hier wird eine Tabelle erzeugt
      eine Html Seite mit css wird der code
      besser lesbar

      Code:
      <?xml version="1.0"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      	<xsl:output indent="yes" method="html"/>
      	<xsl:template match="/">
      		<html>
      			<style type="text/css">
      			
      			table {
      			width:100%;
      			color: red;
      			font-weight: bold;
      			border: 2px SOLID #fc0;
      			}
      			thead {
      			color: black;
      			font-size: 3.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			}
      			th {
      			color: black;
      			font-size: 2.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			background-color:#ff99AA;
      			}
      			td{
      			color: black;
      			font-size: 1.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			}
      			.gerade{
       			background-color:#ff9900;
      			}
      			.ungerade{
       			background-color:#ff99FF;
      			}
      			</style>
      			<xsl:apply-templates select="Patientenkartei"/>
      		</html>
      	</xsl:template>
      
      
      	<xsl:template match="Patientenkartei">
      		<table>
      			<thead>Geburtstag aller Patienten</thead>
      			<tr>
      				<th>NR.</th>
      				<th>Nachname</th>
      				<th>Vorname</th>
      				<th>Geburtstag</th>
      			</tr>
      			<xsl:apply-templates select="Patient"/>
      		</table>
      	</xsl:template>
      
      
      
      	<xsl:template match="Patient">
      		<tr>
      			<xsl:choose>
      				<xsl:when test="position()mod 2=1">
      					<xsl:attribute name="class">ungerade</xsl:attribute>
      				</xsl:when>
      				<xsl:otherwise>
      					<xsl:attribute name="class">gerade</xsl:attribute>
      				</xsl:otherwise>
      			</xsl:choose>
      			<td>
      				<xsl:value-of select="position()"/>
      			</td>
      			<td>
      				<xsl:value-of select="Nachname"/>
      			</td>
      			<td>
      				<xsl:apply-templates select="Vorname"/>
      			</td>
      			<td>
      				<xsl:apply-templates select="Geburtsdatum"/>
      			</td>
      		</tr>
      	</xsl:template>
      </xsl:stylesheet>

      ergebnis

      Code:
      <html>
        <style type="text/css">
      			
      			table {
      			width:100%;
      			color: red;
      			font-weight: bold;
      			border: 2px SOLID #fc0;
      			}
      			thead {
      			color: black;
      			font-size: 3.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			}
      			th {
      			color: black;
      			font-size: 2.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			background-color:#ff99AA;
      			}
      			td{
      			color: black;
      			font-size: 1.5em;
      			border: 2px SOLID #f00;
      			text-align:center;
      			}
      			.gerade{
       			background-color:#ff9900;
      			}
      			.ungerade{
       			background-color:#ff99FF;
      			}
      			
        </style>
        <table>
          <thead>Geburtstag aller Patienten</thead>
          <tr>
            <th>NR.</th>
            <th>Nachname</th>
            <th>Vorname</th>
            <th>Geburtstag</th>
          </tr>
          <tr class="ungerade">
            <td>1</td>
            <td>AAA</td>
            <td>A1</td>
            <td>27011991</td>
          </tr>
          <tr class="gerade">
            <td>2</td>
            <td>BBB</td>
            <td>B2</td>
            <td>27011991</td>
          </tr>
          <tr class="ungerade">
            <td>3</td>
            <td>CCC</td>
            <td>C3</td>
            <td>27011991</td>
          </tr>
          <tr class="gerade">
            <td>4</td>
            <td>DDD</td>
            <td>D4</td>
            <td>27011991</td>
          </tr>
          <tr class="ungerade">
            <td>5</td>
            <td>EEE</td>
            <td>E5</td>
            <td>27011991</td>
          </tr>
        </table>
      </html>

      durch einfügen in der xml
      kan man das ergebniss im browser anschauen


      Code:
      <?xml version="1.0"?>
      <?xml-stylesheet type="text/xsl" href="Patient.xsl"?>
      <Patientenkartei>
      	<Patient>
      		<Nachname>AAA</Nachname>
      		<Vorname>A1</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>BBB</Nachname>
      		<Vorname>B2</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>CCC</Nachname>
      		<Vorname>C3</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>DDD</Nachname>
      		<Vorname>D4</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      	<Patient>
      		<Nachname>EEE</Nachname>
      		<Vorname>E5</Vorname>
      		<Geburtsdatum>27011991</Geburtsdatum>
      	</Patient>
      </Patientenkartei>
      Zuletzt editiert von xml-looser; 17.07.2009, 13:36. Reason: was vergessen

      Comment

      Working...
      X