|
|
Cálculo numérico em XSL
|
O número das funções transforma seu argumento para numerar. O stylesheet 1 de XSL demonstra a conversão de corda, conversos que do stylesheet 2 de XSL os valores booleanos a qualquer um rectificam e falso.
|
XSL stylesheet 1
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE border="1">
<TR>
<TH>text</TH>
<TH>number</TH>
</TR>
<xsl:for-each select="//text">
<TR>
<TD>
<xsl:value-of select="."/>
</TD>
<TD>
<xsl:value-of select="number()"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
XSL stylesheet 2
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE border="1">
<TR>
<TH>text</TH>
<TH>number</TH>
</TR>
<xsl:for-each select="//text[text() = 'true' or text() = 'false()']">
<TR>
<TD>
<xsl:value-of select="."/>
</TD>
<TD>
<xsl:value-of select="number()"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
<P>
<xsl:text>but:</xsl:text>
</P>
<TABLE border="1">
<TR>
<TH>function</TH>
<TH>number</TH>
</TR>
<TR>
<TD>true()</TD>
<TD>
<xsl:value-of select="number(true())"/>
</TD>
</TR>
<TR>
<TD>false()</TD>
<TD>
<xsl:value-of select="number(false())"/>
</TD>
</TR>
<TR>
<TD>5>7</TD>
<TD>
<xsl:value-of select="number(5 > 7)"/>
</TD>
</TR>
<TR>
<TD>5<7</TD>
<TD>
<xsl:value-of select="number(5<7)"/>
</TD>
</TR>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
Operações de Arithematic
|
A adição, subtrai e multiplica usa a sintaxe comum, vê o stylesheet 1 de XSL. A sintaxe da divisão é mais menos usual. “Do slash/” símbolo é usado nos testes padrões e assim que o keyword div é usado preferivelmente, vê o stylesheet 2 de XSL. A modificação do operador retorna um restante de truncar a divisão.
|
XML Source
<source>
<number>1</number>
<number>3</number>
<number>4</number>
<number>17</number>
<number>8</number>
<number>11</number>
</source>
|
Output
<P>1 + 3 = 4</P>
<P>4 - 17 = -13</P>
<P>8 * 11 = 88</P>
|
|
XSL stylesheet 1
<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>
|
|
XML Source
<source>
<number>1</number>
<number>3</number>
<number>4</number>
<number>17</number>
<number>8</number>
<number>11</number>
</source>
|
Output
<P>8 / 11 = 0.7272727272727273</P>
<P>8 mod 11 = 8</P>
|
|
XSL stylesheet 2
<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>
|
|
Teto, assoalho e redondo
|
O ceilng das funções (), o assoalho () e o círculo () transformam números de um ponto flutuando em um inteiro em uma maneira especificada.
|
XML Source
<source>
<number>6</number>
<number>3.8</number>
<number>1.234</number>
<number>-6</number>
<number>-3.8</number>
<number>-1.234</number>
</source>
|
Output
<TABLE border="1">
<TR>
<TH>number</TH>
<TH>floor</TH>
<TH>ceiling</TH>
<TH>round</TH>
</TR>
<TR>
<TD>6</TD>
<TD>6</TD>
<TD>6</TD>
<TD>6</TD>
</TR>
<TR>
<TD>3.8</TD>
<TD>3</TD>
<TD>4</TD>
<TD>4</TD>
</TR>
<TR>
<TD>1.234</TD>
<TD>1</TD>
<TD>2</TD>
<TD>1</TD>
</TR>
<TR>
<TD>-6</TD>
<TD>-6</TD>
<TD>-6</TD>
<TD>-6</TD>
</TR>
<TR>
<TD>-3.8</TD>
<TD>-4</TD>
<TD>-3 |
|
</TR>
<TR>
<TD>-1.234</TD>
<TD>-2</TD>
<TD>-1</TD>
<TD>-1</TD>
</TR>
</TABLE>
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE border="1">
<TR>
<TH>number</TH>
<TH>floor</TH>
<TH>ceiling</TH>
<TH>round</TH>
</TR>
<xsl:for-each select="//number">
<TR>
<TD>
<xsl:value-of select="."/>
</TD>
<TD>
<xsl:value-of select="floor(.)"/>
</TD>
<TD>
<xsl:value-of select="ceiling(.)"/>
</TD>
<TD>
<xsl:value-of select="round(.)"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
Função da corda
|
A corda da função () transforma todo seu argumento na corda. Esta função não é usada diretamente usualy nos stylesheets desde que em a maioria dos casos é chamada pelo defeito. O stylesheet 1 de XSL mostra exemplos dos números às conversões de corda. Observar os resultados do as divisões zero.
|
XML Source
<source>
<number>9</number>
<number>0</number>
<number>-9</number>
<number/>
</source>
|
Output
<P>9</P>
<P>NaN</P>
<P>9/0 = Infinity</P>
<P>-9/0 = -Infinity</P>
<P>0/0 = NaN</P>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="A" select="number(//number[1])"/>
<xsl:variable name="B" select="number(//number[2])"/>
<xsl:variable name="C" select="number(//number[3])"/>
<xsl:variable name="D" select="number(//number[4])"/>
<xsl:template match="/">
<P>
<xsl:value-of select="string(number($A))"/>
</P>
<P>
<xsl:value-of select="string(number($D))"/>
</P>
<P>
<xsl:value-of select="$A"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$B"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="string($A div $B)"/>
</P>
<P>
<xsl:value-of select="$C"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$B"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="string($C div $B)"/>
</P>
<P>
<xsl:value-of select="$B"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$B"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="$B div $B"/>
</P>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
Keywords Numeric Calculation in XSL, xsl functions, xsl tutorial, xsl examples, xsl javascript,
xsl example, xsl function, xsl date, xsl syntax, xsl variable, xsl text, sql numeric,
c# xsl, java numeric, numeric tutorial, asp numeric, numeric number, xsl select,
xsl xpath, xsl output, oracle numeric, perl numeric, numeric time, mysql numeric,
format numeric, xsl html, sql server numeric, xsl vb net, asp net xsl, vb net numeric,
numeric data type
|