English | >> Français << | Deutsch | Magyar | 中文 | Polski ZVON > Tutorials > XSLT Tutorial
>> Page 38 << | Précédent | Suivant | Contenu | Index des éléments

L'addition, la soustraction et la multiplication emploient une syntaxe commune ( Feuille de style XSLT 1 ). La syntaxe de la division est moins courante. La barre de fraction / servant aux motifs, le mot-clé div est utilisé à la place ( Feuille de style XSLT 2 ). L'opérateur mod renvoie le reste d'une opération de division. ( Feuille de style XSLT 2 )

Feuille de style XSLT 1

Source XML
<source>

<number>1</number>
<number>3</number>
<number>4</number>
<number>17</number>
<number>8</number>
<number>11</number>

</source>

Sortie
<P>1 + 3 = 4</P>
<P>4 - 17 = -13</P>
<P>8 * 11 = 88</P>

Vue HTML

1 + 3 = 4

4 - 17 = -13

8 * 11 = 88

Feuille de style XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <P>
          <xsl:value-of select="//number[1]"/>
          <xsl:text> + </xsl:text>
          <xsl:value-of select="//number[2]"/>
          <xsl:text> = </xsl:text>
          <xsl:value-of select="//number[1] + //number[2]"/>
     </P>
     <P>
          <xsl:value-of select="//number[3]"/>
          <xsl:text> - </xsl:text>
          <xsl:value-of select="//number[4]"/>
          <xsl:text> = </xsl:text>
          <xsl:value-of select="//number[3] - //number[4]"/>
     </P>
     <P>
          <xsl:value-of select="//number[5]"/>
          <xsl:text> * </xsl:text>
          <xsl:value-of select="//number[6]"/>
          <xsl:text> = </xsl:text>
          <xsl:value-of select="//number[5] * //number[6]"/>
     </P>
</xsl:template>


</xsl:stylesheet>


Feuille de style XSLT 2

Source XML
<source>

<number>1</number>
<number>3</number>
<number>4</number>
<number>17</number>
<number>8</number>
<number>11</number>

</source>

Sortie
<P>8 / 11 = 0.7272727272727273</P>
<P>8 mod 11 = 8</P>

Vue HTML

8 / 11 = 0.7272727272727273

8 mod 11 = 8

Feuille de style XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <P>
          <xsl:value-of select="//number[5]"/>
          <xsl:text> / </xsl:text>
          <xsl:value-of select="//number[6]"/>
          <xsl:text> = </xsl:text>
          <xsl:value-of select="//number[5] div //number[6]"/>
     </P>
     <P>
          <xsl:value-of select="//number[5]"/>
          <xsl:text> mod </xsl:text>
          <xsl:value-of select="//number[6]"/>
          <xsl:text> = </xsl:text>
          <xsl:value-of select="//number[5] mod //number[6]"/>
     </P>
</xsl:template>


</xsl:stylesheet>