English | Français | Deutsch | >> Magyar << | 中文 | Polski ZVON > Tutorials > XSLT Tutorial
>> Oldal 54 << | Előző | Következő | Tartalom | Elem index

A count() függvény az argumentumban megadott elemkészlet elemeinek számával tér vissza.

XSLT stíluslap 1

XML forrás
<source>

<AAA>
     <CCC/>
     <BBB>
          <CCC>Carl</CCC>
     </BBB>
     <BBB/>
     <BBB/>
</AAA>
<AAA>
     <CCC/>
     <BBB/>
     <BBB>
          <CCC>John</CCC>
          <CCC>Charles</CCC>
          <CCC>Robert</CCC>
          <CCC>Anthony</CCC>
     </BBB>
</AAA>

</source>

Kimenet
<DIV>
  <B>//AAA : </B>2</DIV>
<DIV>
  <B>//CCC : </B>7</DIV>
<DIV>
  <B>//AAA/CCC : </B>2</DIV>
<DIV>
  <B>//CCC[text()]) : </B>5</DIV>

HTML nézet
//AAA : 2
//CCC : 7
//AAA/CCC : 2
//CCC[text()]) : 5
XSLT stíluslap
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <DIV>
          <B>
               <xsl:text>//AAA : </xsl:text>
          </B>
          <xsl:value-of select="count(//AAA)"/>
     </DIV>
     <DIV>
          <B>
               <xsl:text>//CCC : </xsl:text>
          </B>
          <xsl:value-of select="count(//CCC)"/>
     </DIV>
     <DIV>
          <B>
               <xsl:text>//AAA/CCC : </xsl:text>
          </B>
          <xsl:value-of select="count(//AAA/CCC)"/>
     </DIV>
     <DIV>
          <B>
               <xsl:text>//CCC[text()]) : </xsl:text>
          </B>
          <xsl:value-of select="count(//CCC[text()])"/>
     </DIV>
</xsl:template>


</xsl:stylesheet>