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

Параметры шаблону можно передать при помощи элемента xsl:with-param. Если шаблон содержит элемент xsl:param с таким же атрибутом name, что и xsl:with-param, то его значение будет использовано. Преобразование 1 является типичным примером. Если вы хотите передать переменную, то надо определить эту переменную при помощи элемента xsl:param. Примером неправильного подхода может служить преобразование 2.

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

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

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

</source>

Результат
<TABLE>
  <TR>
     <TH>1 (odd)</TH>
  </TR>
  <TR>
     <TH>3 (odd)</TH>
  </TR>
  <TR>
     <TH>4 (even)</TH>
  </TR>
  <TR>
     <TH>17 (odd)</TH>
  </TR>
  <TR>
     <TH>8 (even)</TH>
  </TR>
</TABLE>

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

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//number">
               <TR>
                    <TH>
                         <xsl:choose>
                              <xsl:when test="text() mod 2">
                                   <xsl:apply-templates select=".">
                                        <xsl:with-param name="type">odd</xsl:with-param>
                                   </xsl:apply-templates>
                              </xsl:when>
                              <xsl:otherwise>
                                   <xsl:apply-templates select="."/>
                              </xsl:otherwise>
                         </xsl:choose>
                    </TH>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>

<xsl:template match="number">
     <xsl:param name="type">even</xsl:param>
     <xsl:value-of select="."/>
     <xsl:text> (</xsl:text>
     <xsl:value-of select="$type"/>
     <xsl:text>)</xsl:text>
</xsl:template>


</xsl:stylesheet>



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

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

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

</source>

Результат
<TABLE>
  <TR>
     <TH>1 (even)</TH>
  </TR>
  <TR>
     <TH>3 (even)</TH>
  </TR>
  <TR>
     <TH>4 (even)</TH>
  </TR>
  <TR>
     <TH>17 (even)</TH>
  </TR>
  <TR>
     <TH>8 (even)</TH>
  </TR>
</TABLE>

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

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//number">
               <TR>
                    <TH>
                         <xsl:choose>
                              <xsl:when test="text() mod 2">
                                   <xsl:apply-templates select=".">
                                        <xsl:with-param name="type">odd</xsl:with-param>
                                   </xsl:apply-templates>
                              </xsl:when>
                              <xsl:otherwise>
                                   <xsl:apply-templates select="."/>
                              </xsl:otherwise>
                         </xsl:choose>
                    </TH>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>

<xsl:template match="number">
     <xsl:variable name="type">even</xsl:variable>
     <xsl:value-of select="."/>
     <xsl:text> (</xsl:text>
     <xsl:value-of select="$type"/>
     <xsl:text>)</xsl:text>
</xsl:template>


</xsl:stylesheet>

Raleigh.ruCopyright © 2002

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of stanton
internetusers
This is the website that has all the latest for surf, skate and snow. You can also see it here:. You'll be glad you saw the surf apparel.

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

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