It depends on situation. If you are in the middle
<xsl:apply-templates select="/parent/child" />
Then using
<xsl:if test="position() < 4">
will do. If you are in a different context that does not affect all <child> elements, then position() will refer to the position in that context.
If you need a context check, you can use:
<xsl:if test="count(preceding-sibling::child) < 3"> <xsl:if test="count(preceding-sibling::*) < 3">
To select only the first three <child> elements, it will be:
/parent/child[position() < 4]
Tomalak
source share