11

In XLST how would you find out the length of a node-set?

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75

3 Answers3

13
<xsl:variable name="length" select="count(nodeset)"/>
Theo
  • 131,503
  • 21
  • 160
  • 205
9

there is no need to put that into a

<xsl:variable name="length" select="count(nodes/node)"/>

though... you can just print it out as follows:

<xsl:value-of select="count(nodes/node)"/>

or use it in a if-clause as follows:

<xsl:if test="count(comments/comment) > '0'">
    <ul>
        <xsl:apply-templates select="comments/comment"/>
    </ul>
</xsl:if>
Pierre Spring
  • 10,525
  • 13
  • 49
  • 44
4

Generally in XSLT things aren't referred to as Arrays, since there is really no such thing in XSLT. The technical term is either nodesets (made up of zero or more nodes) or in XSLT 2.0 sequences.

samjudson
  • 56,243
  • 7
  • 59
  • 69