简体   繁体   中英

What is a sequence constructor in XSLT 2.0?

I looked a the spec and some other documents but I dont really get it. I get that now there are sequences instead of nodesets, okay, but what is a sequence constructor (or may more easily: what ISNT a sequence constructor)?

The spec just says

[Definition: A sequence constructor is a sequence of zero or more sibling nodes in the stylesheet that can be evaluated to return a sequence of nodes and atomic values. The way that the resulting sequence is used depends on the containing instruction.]

Many XSLT elements, and also literal result elements, are defined to take a sequence constructor as their content.

I kinda get that xsl:sequence constructs a sequence, but why is the content of xsl:element a sequence constructor? And what isnt a sequence constructor then?

Thanks for clarifications!

See further down in the spec where it says

The term sequence constructor replaces template as used in XSLT 1.0. The change is made partly for clarity (to avoid confusion with template rules and named templates), but also to reflect a more formal definition of the semantics. Whereas XSLT 1.0 described a template as a sequence of instructions that write to the result tree, XSLT 2.0 describes a sequence constructor as something that can be evaluated to return a sequence of items; what happens to these items depends on the containing instruction.

So where the XSLT 1.0 grammar had for instance

<!-- Category: top-level-element -->
<xsl:template
  match = pattern
  name = qname
  priority = number
  mode = qname>
  <!-- Content: (xsl:param*, template) -->
</xsl:template>

allowing as the contents of an xsl:template rule a number of xsl:param plus a template the XSLT 2.0 grammar now has

<!-- Category: declaration -->
<xsl:template
  match? = pattern
  name? = qname
  priority? = number
  mode? = tokens
  as? = sequence-type>
  <!-- Content: (xsl:param*, sequence-constructor) -->
</xsl:template>

defining the contents of an xsl:template rule as a number of xsl:param plus a sequence constructor.

That way it is also obvious that xsl:param is not a sequence constructor for instance but of course as its content has a sequence constructor.

As for how to construct a sequence, well you can do that with literal result elements and of course with instructions like xsl:value-of , xsl:element , xsl:attribute and so on, as well as with xsl:sequence (to allow you to construct and return (sequences of) primitive values and not only nodes, as it was only possible in XSLT 1.0).

Pretty much anywhere you can put a literal result element is a sequence constructor, eg

<xsl:template match="/">
   <a></a>
</xsl:template>

...or

<xsl:variable name="a">
   <a></a>
</xsl:variable>

...but not

<xsl:choose>
   <a></a>
</xsl:choose>

...because the xsl:choose instruction doesn't allow it:

<xsl:choose>
  <!-- Content: (xsl:when+, xsl:otherwise?) -->
</xsl:choose>

So, sequence constructors are places where values, and instructions that create values, go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM