I'm struggling to find a good explanantion of what is and isnt possible for variable types in XSLT 3+ (which I believe uses XPath sequence type syntax)
If I have a template/function/variable that is an element of type Foo I do this
<xsl:variable name="foo" as="element(Foo)*">
<Foo/>
</xsl:variable>
My specific problem is annotating some output with comments (actually in a template, but a variable will do), but the issue is general:
<xsl:variable name="foo" as="element(Foo)*">
<xsl:comment>Foo</xsl:comment>
<Foo/>
</xsl:variable>
this fails (saxon 11.4)
the supplied value <!--...--> does not match. The supplied value is a comment node
Is there a way to define a union type?
The type system in XSLT 3.0 (or XPath 3.0) does not include a general union operator. You can define the union of any two atomic types, but not of other types such as node types, array types, or map types. The best you can do is use the "least common super type" which for element()
and comment()
is node()
.
XSLT match patterns allow match="element()|comment()"
, but that's a match pattern, not an item type, so it can't be used in an as
attribute.