Announcement

Collapse
No announcement yet.

xsl ausgabe mithilfe von parametern eingrenzen

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

  • xsl ausgabe mithilfe von parametern eingrenzen

    Hi, ich hoffe ihr könnt mir helfen. Ich stehe vor folgender Problemstellung.

    Ich hbae diese xml datei:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="style.xsl"?>
    <europa>
       <land>
          <name name="titel">Deutschland</name>
          <einwohnerzahl einheit="Millionen">82.4</einwohnerzahl>
          <hauptstadt>Berlin</hauptstadt>
          <kfz-kennzeichen>D</kfz-kennzeichen>
          <tel-vorwahl>0049</tel-vorwahl>
       </land>
       <land>
          <name name="titel">Frankreich</name>
          <einwohnerzahl einheit="Millionen">58.5</einwohnerzahl>
          <hauptstadt>Paris</hauptstadt>
          <kfz-kennzeichen>F</kfz-kennzeichen>
          <tel-vorwahl>0033</tel-vorwahl>
       </land>
       <land>
          <name name="titel">Spanien</name>
          <einwohnerzahl einheit="Millionen">39.4</einwohnerzahl>
          <hauptstadt>Madrid</hauptstadt>
          <kfz-kennzeichen>E</kfz-kennzeichen>
          <tel-vorwahl>0034</tel-vorwahl>
       </land>
    </europa>
    mit dieser dazugehörigen XSl datei:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="Land"/>
    
    <xsl:template match="europa">
     <html>
      <head>
        <title>Europa xml - xslt</title>
      </head>
      <body>
        <h1>Europa</h1>
        <xsl:apply-templates/>
      </body>
     </html>
    </xsl:template>
    
    <xsl:template match="name">
      <h2>Land: 
      <a>
      <xsl:attribute name="name">
      <xsl:value-of select="."/>
      </xsl:attribute>
      </a>
      <xsl:apply-templates/>
      </h2>
     </xsl:template>
    
     <xsl:template match="einwohnerzahl">
      <br/>
      Einwohner: <xsl:apply-templates/> Millionen
      </xsl:template>
      <xsl:template match="hauptstadt">
      <br/>
      Hauptstadt: <xsl:apply-templates/>
      <xsl:text> - </xsl:text>
      </xsl:template>
    
     <xsl:template match="kfz-kennzecihen">
      <br/>
      Kennzeichen: <xsl:apply-templates/>
      </xsl:template>
      <xsl:template match="tel-vorwahl">
      <br/>
      Vorwahl: <xsl:apply-templates/>
      <br/>
        <hr/>
     </xsl:template>
    
    </xsl:stylesheet>
    Nun möchte ich, wenn der parameter Land=Deutschland ist soll auch nur Deutschland ausgegeben werden.
    Wie könnte ich das hinbekommen?

    Danke

  • #2
    Hallo,
    ich würde es so machen:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
      <xsl:apply-templates select="europa">
        <xsl:with-param name="Land" select="'Deutschland'" />
      </xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="europa">
      <xsl:param name="Land"/>
      <html>
        <head>
          <title>Europa xml - xslt</title>
        </head>
        <body>
          <h1>Europa</h1>
          <xsl:apply-templates select="land[name=$Land]"/>
        </body>
      </html>
    </xsl:template>
    
    <xsl:template match="land">
      <xsl:apply-templates />
    </xsl:template>
    
    <xsl:template match="name">
      <h2>Land:
        <a>
          <xsl:attribute name="name">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </a>
        <xsl:value-of select="." />
      </h2>
    </xsl:template>
    
    <xsl:template match="einwohnerzahl">
      <br/>Einwohner:
      <xsl:value-of select="." />
      Millionen
    </xsl:template>
    
    <xsl:template match="hauptstadt">
      <br/>Hauptstadt:
      <xsl:value-of select="." />
      <xsl:text> - </xsl:text>
    </xsl:template>
    
    <xsl:template match="kfz-kennzeichen">
      <br/>Kennzeichen:
      <xsl:value-of select="." />
    </xsl:template>
    
    <xsl:template match="tel-vorwahl">
      <br/>Vorwahl:
      <xsl:value-of select="." />
      <br/><hr/>
    </xsl:template>
    
    </xsl:stylesheet>

    Comment

    Working...
    X