I have the same issue when writing custom functions for XPath evaluation in .NET C#, using XSLT inheritance. When text() is provided as argument, it turns into the type XPathSelectionIterator that is mentioned in the question's title.
The solution for me was to match it with the XPathNodeIterator type in a pattern and access the string as Current?.Value.
var stringValue = arg[0] switch
{
string s => s,
XPathNodeIterator i => i.Current?.Value ?? ""
_ => ""
};