<html>
<head>
<title>&lt;xsl:if&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Beschreibung">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:if&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Diese Anweisung implementiert eine <span class="LITERAL">if</span>-Anweisung. Sie enth&auml;lt ein <span class="LITERAL">test</span>-Attribut und eine XSLT-Vorlage. Ergibt das Attribut <span class="LITERAL">test</span> den Booleschen Wert <span class="LITERAL">true</span>, so wird die XSLT-Vorlage verarbeitet. Dieses Element implementiert nur eine <span class="LITERAL">if</span>-Anweisung. Wenn Sie hingegen eine <span class="LITERAL">if-then-else</span>-Anweisung ben&ouml;tigen, verwenden Sie das Element <span class="LITERAL">&lt;xsl:choose&gt;</span> zusammen mit einem einzigen <span class="LITERAL">&lt;xsl:when&gt;</span> und einem einzigen <span class="LITERAL">&lt;xsl:otherwise&gt;</span>.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Kategorie</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Anweisung</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Obligatorische Attribute</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
test
</dt>
<dd>
Das Attribut <span class="LITERAL">
test
</span> enth&auml;lt einen Booleschen Ausdruck. Ergibt das Attribut den Booleschen Wert <span class="LITERAL">true</span>, so wird die XSLT-Vorlage innerhalb von <span class="LITERAL"> &lt; xsl:if &gt; </span>verarbeitet.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optionale Attribute</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Keine</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Inhalt</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Eine XSLT-Vorlage</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">&Uuml;bergeordnetes Element</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:if&gt;</span> erscheint innerhalb einer Template.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Definition</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT-Abschnitt 9.1, Bedingte Verarbeitung mit <span class="LITERAL">xsl:if</span></p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Beispiel</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Die Funktionsweise des Elements <span class="LITERAL">&lt;xsl:if&gt;</span> wird durch das folgende Stylesheet veranschaulicht:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;Here are the odd-numbered items from the list:&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:for-each select="list/listitem"&gt;
      &lt;xsl:if test="(position() mod 2) = 1"&gt;
        &lt;xsl:number format="1. "/&gt;
        &lt;xsl:value-of select="."/&gt;
        &lt;xsl:value-of select="$newline"/&gt;
      &lt;/xsl:if&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  
&lt;/xsl:stylesheet&gt;</pre></span>
<p>Dieses Stylesheet verwendet das Element <span class="LITERAL">&lt;xsl:if&gt;</span>, um festzustellen, ob es sich bei der Position eines bestimmten <span class="LITERAL">&lt;listitem&gt;</span> um eine ungerade Zahl handelt. Ist das der Fall, wird sie in den Ergebnisbaum geschrieben. Dieses Stylesheet wird mit dem folgenden Dokument getestet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list&gt;
  &lt;title&gt;A few of my favorite albums&lt;/title&gt;
  &lt;listitem&gt;A Love Supreme&lt;/listitem&gt;
  &lt;listitem&gt;Beat Crazy&lt;/listitem&gt;
  &lt;listitem&gt;Here Come the Warm Jets&lt;/listitem&gt;
  &lt;listitem&gt;Kind of Blue&lt;/listitem&gt;
  &lt;listitem&gt;London Calling&lt;/listitem&gt;
  &lt;listitem&gt;Remain in Light&lt;/listitem&gt;
  &lt;listitem&gt;The Joshua Tree&lt;/listitem&gt;
  &lt;listitem&gt;The Indestructible Beat of Soweto&lt;/listitem&gt;
&lt;/list&gt;</pre></span> <!--<?troff .Nd 10?>-->
<p>Hier die Ergebnisse, die entstehen, wenn diese Transformation ausgef&uuml;hrt wird:</p>
<span class="PROGRAMLISTING"><pre>
Here are the odd-numbered items from the list:
1. A Love Supreme
3. Here Come the Warm Jets
5. London Calling
7. The Joshua Tree</pre></span>
</td>
</tr>
</table>
</div>
</body>
</html>
