Главная -> XML&... -> XSLT в примерах 
>> Страница 39 << | Назад | Вперед | Содержание | Указатель

Функция sum() суммирует все числа из выбранного множества узлов. В преобразовании 1 суммируются все числа, а в преобразовании 2 — только нечетные.

Преобразование 1

Исходный Surf
<source>

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

</source>

Результат
1 + 3 + 4 + 17 + 8 + 11 = 44

Представление HTML
1 + 3 + 4 + 17 + 8 + 11 = 44
Преобразование XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <xsl:for-each select="//number">
          <xsl:value-of select="."/>
          <xsl:choose>
               <xsl:when test="position()=last()">
                    <xsl:text> = </xsl:text>
               </xsl:when>
               <xsl:otherwise>
                    <xsl:text> + </xsl:text>
               </xsl:otherwise>
          </xsl:choose>
     </xsl:for-each>
     <xsl:value-of select="sum(//number)"/>
</xsl:template>


</xsl:stylesheet>



Преобразование 2

Исходный Surf
<source>

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

</source>

Результат
1 + 3 + 17 + 11 = 32

Представление HTML
1 + 3 + 17 + 11 = 32
Преобразование XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <xsl:for-each select="//number">
          <xsl:variable name="number" select="."/>
          <xsl:if test="$number mod 2">
               <xsl:value-of select="."/>
               <xsl:choose>
                    <xsl:when test="position()=last()">
                         <xsl:text> = </xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                         <xsl:text> + </xsl:text>
                    </xsl:otherwise>
               </xsl:choose>
          </xsl:if>
     </xsl:for-each>
     <xsl:value-of select="sum(//number[text() mod 2 = true()])"/>
</xsl:template>


</xsl:stylesheet>

Raleigh.ruCopyright © 2002

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of stanton
internetusers

City Of Stanton | City Of Stanton | Warren Stanton Council and Gary Taylor Stanton | City Of Stanton |



Take a moment to visit 1cecilia438 or see them on twitter at 1cecilia410 or view them on facebook at hawaiian luxury shoes.

Take a moment to visit 1cecilia448 or see them on twitter at 1cecilia448 or view them on facebook at 1cecilia448.

Also, visit the website of Jeff Hiatt and buy his orange oil for termite control.

And if you have a chance, and you live in Orange County California, you might want to know about the City of Stanton. Follow the links below and learn more here:

City of Stanton kevin carr Stanton California Stanton City Hall Kevin Carr in Stanton

You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks