我查看了规范和其他一些文档,但我不太明白。我知道现在有序列而不是节点集,好吧,但是什么是序列构造函数(或者更简单:什么不是序列构造函数)?
规范只是说
[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.]
block 引用>Many XSLT elements, and also literal result elements, are defined to take a sequence constructor as their content.
我有点明白 xsl:sequence 构造了一个序列,但是为什么 xsl:element 的内容是一个序列构造函数?那么什么不是序列构造函数呢?
感谢您的澄清!
最佳答案
请参阅规范中的进一步内容
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.
例如,XSLT 1.0 语法在哪里
<!-- Category: top-level-element -->
<xsl:template
match = pattern
name = qname
priority = number
mode = qname>
<!-- Content: (xsl:param*, template) -->
</xsl:template>
允许将许多 xsl:param
加上一个 template
作为 xsl:template
规则的内容,XSLT 2.0 语法现在具有
<!-- Category: declaration -->
<xsl:template
match? = pattern
name? = qname
priority? = number
mode? = tokens
as? = sequence-type>
<!-- Content: (xsl:param*, sequence-constructor) -->
</xsl:template>
将 xsl:template
规则的内容定义为多个 xsl:param
加上序列构造函数。
这样,很明显 xsl:param
不是一个序列构造函数,但当然,因为它的内容有一个序列构造函数。
至于如何构造序列,您可以使用文字结果元素,当然也可以使用诸如 xsl:value-of
、xsl:element
、 xsl:attribute
等等,以及 xsl:sequence
(允许您构造和返回原始值(的序列),而不仅仅是节点,因为它是仅在 XSLT 1.0 中可能)。
关于xslt - XSLT 2.0 中的序列构造函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629339/