Ataman
Ataman

Reputation: 2590

Count siblings of a variable in xsl

I want to perform a simple xpath but coudnt manage to do it.. I create a variable in xsl file as follows:

<xsl:variable name="list_of_rules">
            <rules>s</rules>
            <rules>np</rules>
</xsl:variable>

Then I try to perform something like this

<xsl:value-of select="count(preceding-sibling::$list_of_rules/rules[. = 'np'])"></xsl:value-of>

This is not working obviously but all i want to do is count the preceding sibling in list_of_rules variable with given text. I cannot create this list_of_rules variable as i dont have apermission to update xml or xsd files.

Thanks

Upvotes: 2

Views: 178

Answers (1)

Wayne
Wayne

Reputation: 60424

You just need to invert your thinking. Use the following expression:

count($list_of_rules/rules[.='np']/preceding-sibling::*)

Upvotes: 3

Related Questions