Counting certain preeceding siblings

Ian Gibbs

Usenet Archive
Joined
May 20, 2004
Messages
2
Reaction score
0
Dear all,

I'd like to know in the following XML, when I am looping through the server elements, how many of the previous servers had ldap-role values of YES or MASTER.

<install-config>
<servers>
<server hostname="server1">
<ldap-role>NO</ldap-role>
</server>
<server hostname="server2">
<ldap-role>MASTER</ldap-role>
</server>
<server hostname="server3">
<ldap-role>YES</ldap-role>
</server>
</servers>
</install-config>

So for server 2, I want a value of 0, because there are 0 preceding siblings that have ldap-role values of YES/MASTER, and a value of 1 for server3. I think everything I've tried hasn't worked because I haven't quite grasped how what I want relates to the context node (which I think is the server). Here's my XSLT:

<xsl:template match="install-config">
<install-config>
<servers>
<xsl:for-each select="servers/server"> <!-- for each server --> <server> <xsl:if test="ldap-role='MASTER' or ldap-role='YES'"> <ldap-role> <instance-alias><xsl:value-of select="insert-expression-here"/></instance-alias> </ldap-role> </xsl:if> </server> </xsl:for-each> </servers> </install-config> </xsl:template>

Many thanks in advance for anybody's help.

Regards,
Ian Gibbs
 

Ben Edgington

Usenet Archive
Joined
Mar 18, 2004
Messages
45
Reaction score
0
I'd like to know in the following XML, when I am looping through the server elements, how many of the previous servers had ldap-role values of YES or MASTER.

<install-config>
<servers>
<server hostname="server1">
<ldap-role>NO</ldap-role>
</server>
<server hostname="server2">
<ldap-role>MASTER</ldap-role>
</server>
<server hostname="server3">
<ldap-role>YES</ldap-role>
</server>
</servers>
</install-config>

So for server 2, I want a value of 0, because there are 0 preceding siblings that have ldap-role values of YES/MASTER, and a value of 1 for server3. I think everything I've tried hasn't worked because I haven't quite grasped how what I want relates to the context node (which I think is the server). Here's my XSLT:

<xsl:template match="install-config">
<install-config>
<servers>
<xsl:for-each select="servers/server"> <!-- for each server --> <server> <xsl:if test="ldap-role='MASTER' or ldap-role='YES'"> <ldap-role> <instance-alias><xsl:value-of select="insert-expression-here"/></instance-alias> </ldap-role> </xsl:if> </server> </xsl:for-each> </servers> </install-config> </xsl:template>

Replacing insert-expression-here with
count(preceding-sibling::server[ldap-role='MASTER' or ldap-role='YES']) gives me a plausible result. Is that what you want?

Ben
 

Ian Gibbs

Usenet Archive
Joined
May 20, 2004
Messages
2
Reaction score
0
Ben Edgington said:
Replacing insert-expression-here with
count(preceding-sibling::server[ldap-role='MASTER' or ldap-role='YES']) gives me a plausible result. Is that what you want?

Ben

That's it! Thanks very much.

Regards,
Ian Gibbs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top