diff --git a/specifications/xslt-40/src/element-catalog.xml b/specifications/xslt-40/src/element-catalog.xml index 9a4603ae4..0131fe55b 100644 --- a/specifications/xslt-40/src/element-catalog.xml +++ b/specifications/xslt-40/src/element-catalog.xml @@ -1654,6 +1654,9 @@ + + + diff --git a/specifications/xslt-40/src/schema-for-xslt40.xsd b/specifications/xslt-40/src/schema-for-xslt40.xsd index d72aa36c2..d7969ffc5 100644 --- a/specifications/xslt-40/src/schema-for-xslt40.xsd +++ b/specifications/xslt-40/src/schema-for-xslt40.xsd @@ -405,8 +405,10 @@ of problems processing the schema using various tools + + diff --git a/specifications/xslt-40/src/xslt.xml b/specifications/xslt-40/src/xslt.xml index 2b15d6cb6..3813cba4b 100644 --- a/specifications/xslt-40/src/xslt.xml +++ b/specifications/xslt-40/src/xslt.xml @@ -26039,7 +26039,8 @@ the same group, and the--> which is expanded as described in .

An xsl:accumulator declaration can only appear as a element in a stylesheet module.

- +

The capture attribute is allowed only on an xsl:accumulator-rule element + that specifies phase="end". Its effect is described in .

@@ -26128,7 +26129,9 @@ the same group, and the--> type error occurs if conversion is not possible. The as attribute defaults to item()*.

-

The effect of the streamable attribute is defined in .

+

The effect of the streamable + and capture attributes + are defined in .

@@ -26358,6 +26361,11 @@ the same group, and the--> available for use within the select expression or contained sequence constructor.

+ +

There is a slight variation here for an accumulator rule specifying + phase="end" and capture="yes". For details, + see .

+
@@ -26450,9 +26458,87 @@ the same group, and the--> +
+ + Capturing Accumulators + +

The capture attribute is intended primarily for use with streamable accumulators, but + in the interests of consistency, it has the same effect both for streamable and non-streamable + accumulators. If an accumulator rule with phase="end" specifies capture="yes", + then the rule is evaluated not with the matched node as the context item, but rather with a snapshot + copy of the matched node. The snapshot copy is made following the rules of the snapshot + function, with one exception: no accumulator values are copied into the snapshot tree (which would otherwise + happen: see ).

+ +

The principal effect of specifying capture="yes" is to relax + the rules for streamability. With this option, the phase="end" accumulator rule + has access to the full subtree rooted at the node being visited. In a typical implementation, + a streaming processor encountering an element that matches a capturing accumulator rule + will make an on-the-fly in-memory copy of that element, allowing the phase="end" + accumulator rule full access to the subtree, and also to attributes of ancestors.

+ +

This means that an accumulator that needs access to the typed value or string value of an element + can get this directly with a rule that matches the element, avoiding the need + to write rules that match the element’s text node children. +

+ +

For example, to capture a copy of the most recent h2 element in a document, + the following accumulator might be declared:

+ + + +]]> + +

and subsequent processing wishing to copy the most recent h2 element into the result + tree can simply use <xsl:copy-of select="accumulator-before('most-recent-h2')"/>.

+ +

Without the capture="yes" attribute, this accumulator would be rejected + as non-streamable, because the select expression on the accumulator rule + is consuming.

+ +
+ + + Using a capturing accumulator to construct a glossary +

Suppose a document contains definitions of technical terms with markup such as:

+ In chemistry, + oxidation is a chemical process in which atoms lose electrons.]]> +

and the requirement is to generate a glossary that lists all the defined terms in the document, as an appendix.

+

This can be achieved by capturing all the defined terms in a map:

+ + +]]> +

Suppose that the input XML document contains an element <glossary/> marking + the point where the glossary is to be inserted. The glossary can then be generated + using a template rule such as:

+ +

Glossary

+
+ + +
{?key}
+
+
+
+]]>
+ + +
+ + + +
Streamability of Accumulators + +

An accumulator is if it satisfies all the following @@ -26473,10 +26559,31 @@ the same group, and the--> .

-

The expression in the select attribute or contained - sequence constructor is and - .

+

In an xsl:accumulator-rule with + phase="start" (the default value), + the of + the expression in the select attribute or the contained + , with respect to the declared type of the accumulator, + is and .

+ +

In an xsl:accumulator-rule with + phase="end", one of the + following conditions holds:

+ +

The rule has capture="no" (the default value), + and the of + the expression in the select attribute or the contained + , with respect to the declared type of the accumulator, + is and .

+

The rule has capture="yes" and the of + the expression in the select attribute or the contained + + is or .

+
+
+ + @@ -39233,10 +39340,15 @@ See

Simplified stylesheets no longer require an xsl:version attribute (which means they might not need a declaration of the XSLT namespace). Unless otherwise specified, a 4.0 simplified stylesheet defaults expand-text to true.

+

A new set of built-in template rules is introduced, invoked using <xsl:mode on-no-match="shallow-copy-all">. This is designed to allow rule-based recursive transformation of JSON data structures (trees of maps and arrays) to work in the same way as with XML-derived data structures.

+ +

The streamability rules for accumulators have been relaxed, so that the phase="end" + processing has access to the full subtree of the matched node.

+