Path: redb-route/redb.Route/Expressions/XPathVariableContext.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Expressions/XPathVariableContext.cs
----
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using redb.Route.Abstractions;
namespace redb.Route.Expressions;
///
/// Supplies bound values to the $name variables of an XPath expression.
///
///
///
/// The BCL resolves XPath variables only through an , which it accepts in
/// the same slot as a plain namespace resolver — so one object carries both the prefixes and the
/// values. derives from , which is what
/// makes carrying both natural rather than a trick.
///
///
/// Built per evaluation, because the values come from the message. The path is not rebuilt, which
/// is the whole point: the same query text runs whatever the data.
///
///
internal sealed class XPathVariableContext : XsltContext
{
private readonly Dictionary _values = new(StringComparer.Ordinal);
private XPathVariableContext() : base(new NameTable())
{
}
internal static XPathVariableContext Build(
IXmlNamespaceResolver? namespaces,
IReadOnlyList<(string Name, IExpression Value)> parameters,
IExchange exchange)
{
var context = new XPathVariableContext();
if (namespaces is not null)
{
foreach (var (prefix, uri) in namespaces.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
context.AddNamespace(prefix, uri);
}
foreach (var (name, value) in parameters)
context._values[name] = ToXPathValue(value.Evaluate