Counting certain preeceding siblings

I

Ian Gibbs

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
 
B

Ben Edgington

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
 
I

Ian Gibbs

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top