English | Français | Deutsch | Magyar | 中文 | >> Polski << ZVON > Tutorials > XSLT Tutorial
>> Strona 27 << | Poprzedni | Następny | Zawartość | Indeks elementu

Elementu xsl:choose używa się w sytuacji wyboru jednej z kilku możliwości.

Arkusz stylów XSLT 1

Źródło XML
<source>

<SECTION>
     <DATA>I need a pen.</DATA>
     <DATA>I need some paper.</DATA>
     <SUMMARY>I need a pen and some paper</SUMMARY>
</SECTION>
<SECTION>
     <DATA>I need bread.</DATA>
     <DATA>I need butter.</DATA>
</SECTION>

</source>

Dane wyjściowe
<P>SUMMARY: I need a pen and some paper</P>

<P>DATA: I need bread.</P>
<P>DATA: I need butter.</P>

Widok HTML

SUMMARY: I need a pen and some paper

DATA: I need bread.

DATA: I need butter.

Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="//SECTION">
     <xsl:choose>
          <xsl:when test="SUMMARY">
               <P>
                    <xsl:text>SUMMARY: </xsl:text>
                    <xsl:value-of select="SUMMARY"/>
               </P>
          </xsl:when>
          <xsl:otherwise>
               <xsl:for-each select="DATA">
                    <P>
                         <xsl:text>DATA: </xsl:text>
                         <xsl:value-of select="."/>
                    </P>
               </xsl:for-each>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>


</xsl:stylesheet>