Francesco Irrera
Francesco Irrera

Reputation: 473

Count child number using Xslt 1.0

Return the number of child in a node.

This is my XML:

<LIGHT_INFORMATION_LIST>
    <LIGHT_INFORMATION>
        <LIGHT_COLOUR>W-G</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
    <LIGHT_INFORMATION>
        <LIGHT_COLOUR>W-R</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
    <LIGHT_INFORMATION>
        <LIGHT_COLOUR>R</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
    <LIGHT_INFORMATION>
        <LIGHT_COLOUR>G</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
    <LIGHT_INFORMATION>
        <LIGHT_COLOUR>W</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
</LIGHT_INFORMATION_LIST>

Request Output:
The output request is 5. (The number of child called LIGHT_INFORMATION)

Upvotes: 1

Views: 1460

Answers (1)

Francesco Irrera
Francesco Irrera

Reputation: 473

This is the solution:

<xsl:value-of select="count(LIGHT_INFORMATION_LIST/LIGHT_INFORMATION)"/>

Return 5

Upvotes: 2

Related Questions