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

xsl:number wstawia sformatowany numer. Format jest określny w przez atrybut "format". Wartość atrybutu rozpoczyna się identyfikatorem formatu po których umieszczone są znaki separacji. Kolejne przykłady ilustrują tę notację.

Arkusz stylów XSLT 1

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>1. one</TD>
  </TR>
  <TR>
     <TD>2. two</TD>
  </TR>
  <TR>
     <TD>3. three</TD>
  </TR>
  <TR>
     <TD>4. four</TD>
  </TR>
</TABLE>

Widok HTML
1. one
2. two
3. three
4. four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="1. "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>


Arkusz stylów XSLT 2

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>001. one</TD>
  </TR>
  <TR>
     <TD>002. two</TD>
  </TR>
  <TR>
     <TD>003. three</TD>
  </TR>
  <TR>
     <TD>004. four</TD>
  </TR>
</TABLE>

Widok HTML
001. one
002. two
003. three
004. four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="001. "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>


Arkusz stylów XSLT 3

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>A   one</TD>
  </TR>
  <TR>
     <TD>B   two</TD>
  </TR>
  <TR>
     <TD>C   three</TD>
  </TR>
  <TR>
     <TD>D   four</TD>
  </TR>
</TABLE>

Widok HTML
A one
B two
C three
D four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="A "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>


Arkusz stylów XSLT 4

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>a# one</TD>
  </TR>
  <TR>
     <TD>b# two</TD>
  </TR>
  <TR>
     <TD>c# three</TD>
  </TR>
  <TR>
     <TD>d# four</TD>
  </TR>
</TABLE>

Widok HTML
a# one
b# two
c# three
d# four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="a# "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>


Arkusz stylów XSLT 5

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>i: one</TD>
  </TR>
  <TR>
     <TD>ii: two</TD>
  </TR>
  <TR>
     <TD>iii: three</TD>
  </TR>
  <TR>
     <TD>iv: four</TD>
  </TR>
</TABLE>

Widok HTML
i: one
ii: two
iii: three
iv: four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="i: "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>


Arkusz stylów XSLT 6

Źródło XML
<source>

<n>one</n>
<n>two</n>
<n>three</n>
<n>four</n>

</source>

Dane wyjściowe
<TABLE>
  <TR>
     <TD>I... one</TD>
  </TR>
  <TR>
     <TD>II... two</TD>
  </TR>
  <TR>
     <TD>III... three</TD>
  </TR>
  <TR>
     <TD>IV... four</TD>
  </TR>
</TABLE>

Widok HTML
I... one
II... two
III... three
IV... four
Arkusz stylów XSLT
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <TABLE>
          <xsl:for-each select="//n">
               <TR>
                    <TD>
                         <xsl:number value="position()" format="I... "/>
                         <xsl:value-of select="."/>
                    </TD>
               </TR>
          </xsl:for-each>
     </TABLE>
</xsl:template>


</xsl:stylesheet>