Xpath10 count
xpath10-count · version 1.0.0 · Structured formats · free, no key needed
Count the nodes in an XPath 1.0 node-set from location paths, axes, predicates, namespaces and union.
Use when you need to: count xpath 1.0 node set · how many xml nodes match this xpath · xpath count function for a location path.
Decide before calling
Read the versioned contract and the supported scope below. Reuse xpath10-count@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use xpath10-count@1.0.0 for count xpath 1.0 node set. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- count xpath 1.0 node set
- how many xml nodes match this xpath
- xpath count function for a location path
- size of an xpath union node set
- number of nodes selected by xpath 1.0
- count elements attributes or namespaces by xpath
Not supported
- returning the selected nodes or their paths
- calling count() inside the XPath expression
- XPath 2.0 sequence cardinality and arithmetic
Behavior
- Returns the XPath 1.0 count() of the same node-set xpath10-select would return. The result is {count} and nothing else.
- Union duplicates are eliminated first, so //para | //para on two para elements counts 2.
- //para[1] counts the first para child of each parent. /descendant::para[1] counts one node. / counts the root, which is always 1.
- count(/r), arithmetic, variables and XPath 2.0 syntax are unsupported_input. The count is not computed by evaluating a count() call inside the expression.
- A missing match counts 0. Limits and malformed XML or XPath fail with the same codes as xpath10-select, before a count is returned.
Input
xml(string, required): min length 1; max length 4096expression(string, required): min length 1; max length 1024namespaces(object, optional)
Output
count(integer, required): min 0; max 400
Limits
- max xml bytes: 4096
- max expression bytes: 1024
- max depth: 32
- max nodes: 400
- max steps: 100000
- max output bytes: 32768
- max namespace bindings: 16
- max namespace uri bytes: 512
- max name chars: 256
- max union operands: 32
- max xpath depth: 32
Example
Request input:
{
"xml": "<doc><para>A</para><sec><para>B</para><para>C</para></sec></doc>",
"expression": "//para[1]"
}
Response:
{
"result": {
"count": 2
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "xpath10-count",
"version": "1.0.0",
"input": {
"xml": "<doc><para>A</para><sec><para>B</para><para>C</para></sec></doc>",
"expression": "//para[1]"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/xpath10-count/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"xml":"<doc><para>A</para><sec><para>B</para><para>C</para></sec></doc>","expression":"//para[1]"}'
The machine-readable contract is at /v1/tools/xpath10-count/versions/1.0.0.
CLI
node cli.mjs run xpath10-count 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Xpath10 select: Select an XPath 1.0 node-set from location paths, axes, predicates, namespaces and union, in document order.
- Xpath10 paths: List the canonical XPath 1.0 path of each node in a location-path node-set, in document order.
- Xpath10 boolean: Evaluate an XPath 1.0 boolean expression: comparisons, and, or, not, starts-with, contains, and boolean conversion.
- Xpath10 evaluate: Evaluate an XPath 1.0 value expression and return its type with an exact string, number, or boolean token.
- XML exc c14n subtree: Exclusive XML Canonicalization 1.0 of one selected element and its descendants.
- Xpath10 number: Evaluate an XPath 1.0 numeric expression: arithmetic, div, mod, floor, ceiling, round, and number conversion.