This ensures type safety for comparisons and operations.
The cast will fail at query execution time if the value cannot be converted
to the target type (e.g., casting "abc" to xsd:integer).
Parameters
variable: any
The SPARQL variable to cast (e.g., ?age)
targetType: NamedNode
The target XSD datatype (e.g., xsd.integer, xsd.decimal)
Returns SparqlTemplateResult
SPARQL expression that casts the variable to the target type
Example
// Cast to integer for numeric comparison constcastVar = castVariable(propertyVar, xsd.integer); // Results in: xsd:integer(?age)
Example
// Use in filter filters: [sparql`FILTER(${castVariable(propertyVar, xsd.integer)} >= 18)`]
Cast a SPARQL variable to a specific XSD datatype
This ensures type safety for comparisons and operations. The cast will fail at query execution time if the value cannot be converted to the target type (e.g., casting "abc" to xsd:integer).