Here is a simplified sample of the XML document:
<network>
<node>
<node-id>A</node-id>
<predecessor-id></predecessor-id>
<successor-id>B</successor-id>
</node>
<node>
<node-id>B</node-id>
<predecessor-id>A</predecessor-id>
<successor-id>D</successor-id>
</node>
<node>
<node-id>C</node-id>
<predecessor-id>A</predecessor-id>
<successor-id>D</successor-id>
</node>
<node>
<node-id>D</node-id>
<predecessor-id>B</predecessor-id>
<predecessor-id>C</predecessor-id>
<successor-id></successor-id>
</node>
</network>
<xsl:template match="node">
<xsl:variable name="this-node-id" select="node-id" />
<xsl:variable name="this-predecessor-nodes"
select="predecessor-id" />
<xsl:variable name="other-predecessor-nodes"
select="/network/node[node-id != $this-node-id]" />
<xsl:variable name="sibling-cnt"
select="count($this-predecessor-nodes[count(. |
$other-predecessor-nodes) != count($other-predecessor-nodes)])" />
This node id = <xsl:value-of select="$this-node-id" />
Sibling count = <xsl:value-of select="$sibling-cnt" />
</xsl:template>
</xsl:stylesheet>
Looking at node A,
$this-node-id := "A"
$this-predecessor-nodes := a single empty element with name
<predecessor-id/>
$other-predecessor-nodes := the three <node> elements with node-ids B,
C, and D
$sibling-count := the number of nodes in $this-predecessor-count that
are not present in $other-predecessor-nodes. Since the nodes in these
two sets have different names this will always be comprise all the nodes
in $this-predecessor-nodes.
I haven't tried to understand your algorithm in detail, but I think you
want $predecessor-nodes to be the <node> elements identified by the
<predecessor-node> elements, not the <predecessor-node> elements
themselves.
You expression appears to be computing the set difference, not the
intersection.
I would strongly recommend using keys for this kind of problem.
Michael Kay
This yielded the following output:
<?xml version="1.0" encoding="UTF-8"?>
This node id = A
Sibling count = 1
This node id = B
Sibling count = 1
This node id = C
Sibling count = 1
This node id = D
Sibling count = 2
It the intersection operation didn't do what I expected. I
expected that nodes A and D would have a Sibling count of 0
and that nodes B and C would each have a sibling count of 1.
Could anyone tell me where I'm going wrong and point me in
the right direction? Thanks.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list