Counting nodes in XSLT whose parent nodes have certain attributes
By : John Smith
Date : March 29 2020, 07:55 AM
Hope this helps I have XML like this: , code :
<xsl:variable name="scoredItems"
select="./item/../attributes/variable_name[@value='SCORE']"/>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="section">
<xsl:variable name="scoredItems"
select="self::section[attributes/variable_name/@value='SCORE']/item"/>
<xsl:variable name="scoredItemsCount" select="count($scoredItems)"/>
<xsl:value-of select="$scoredItemsCount"/>
</xsl:template>
</xsl:stylesheet>
3
0
|
Counting number of nodes and leaf nodes in Binary Tree
By : Richard Alves
Date : March 29 2020, 07:55 AM
help you fix your problem You need a recursive call from within these functions but instead you are attempting to create a node and add the node to an integer. You need this sort of changes: code :
count += leaf_nodes(t->leftNode); //BinaryNode(t->leftNode); //line 230
|
Counting the inner nodes (parent nodes) in a binary tree recursively
By : libya 123
Date : March 29 2020, 07:55 AM
Any of those help I need to create a recursive method that takes as a parameter the root node of a binary search tree. This recursive method will then return the int value of the total number of inner nodes in the entire binary search tree. , Here's the recursive method fixed: code :
int countNrOfInnerNodes (Node node) {
if(node == null) {
return 0;
}
if (node.left == null && node.right == null) {
// not an inner node !
return 0;
} else {
// the number of inner nodes in the left sub-tree + the number of inner
// nodes in the right sub-tree, plus 1 for this inner node
return countNrOfInnerNodes(node.left) + countNrOfInnerNodes(node.right) + 1;
}
}
int countNrOfInnerNodes(Node node) {
if (node == null)
return 0;
Stack<Node> nodesToCheck = new Stack<Node>();
nodesToCheck.push(node);
int count = 0;
while (!nodesToCheck.isEmpty()) {
Node checkedNode = nodesToCheck.pop();
boolean isInnerNode = false;
if (node.left != null) {
isInnerNode = true;
nodesToCheck.push(node.left);
}
if (node.right != null) {
isInnerNode = true;
nodesToCheck.push(node.right);
}
if (isInnerNode)
count++;
}
return count;
}
|
XQuery issue when counting empty nodes and nodes that don't have a specific text (ne)
By : Anton
Date : March 29 2020, 07:55 AM
may help you . You can use string() or even more compact, . instead of text() to correctly consider element that doesn't contain any text node : code :
let $r_nodes := count(doc('test.xml')//r[. ne 'unspecified'])
return
$r_nodes
|
counting the specific nodes in a binary tree in which the nodes are chars in c
By : Hyunmin Yang
Date : March 29 2020, 07:55 AM
I hope this helps you . You are not adding the numbers being returned by your children. Also if the node you are evaluating does not have the state you are looking for, your right node is never searched. Below should be a fix. code :
int findStateCount(Node* root, char* state){
int count=0;
if (root!=NULL){
//Check if this node has the state we're looking for
if(strcmp((root-> state),(state))==0)
++count;
}
//Get the number of matches from my children
count += findStateCount(root->left,state);
count += findStateCount(root->right,state);
}
return count;
}
|