MrD at KookerellaLtd
MrD at KookerellaLtd

Reputation: 2807

sequence type syntax and union types

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?

Upvotes: 0

Views: 72

Answers (2)

Michael Kay
Michael Kay

Reputation: 163595

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.

Upvotes: 2

Martin Honnen
Martin Honnen

Reputation: 167716

There is the sequence type node() and then course for sequences of nodes node()* or node()+.

Upvotes: 1

Related Questions