xslt - XSLT 2.0 中的序列构造函数是什么?

标签 xslt constructor

我查看了规范和其他一些文档,但我不太明白。我知道现在有序列而不是节点集,好吧,但是什么是序列构造函数(或者更简单:什么不是序列构造函数)?

规范只是说

[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.

我有点明白 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-ofxsl:elementxsl:attribute 等等,以及 xsl:sequence (允许您构造和返回原始值(的序列),而不仅仅是节点,因为它是仅在 XSLT 1.0 中可能)。

关于xslt - XSLT 2.0 中的序列构造函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629339/

相关文章:

C++:关于对象的一个​​小问题

java - 在 Java 中,可以从构造函数助手初始化最终字段吗?

XSLT、XPath 唯一子节点仅存在根本未选择非唯一节点的问题

python - 要汇总的 XML 文件

OR 条件语句的 XSLT 较短版本

javascript - 未捕获的类型错误 : "(function call) is not a function"

java类调用/调用jsp文件

java - 使用类构造函数设置数组值时出现 NullPointerException

xslt - 使用 XSLT 从文本文件中删除第一行

xslt调用java实例方法