Like this:

LikeLoading...

Related

This entry was posted on Friday, April 22nd, 2005 at 2:34 pm and is filed under Cocoon. You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.

Post navigation

5 Responses to Recursion in XSLT is fun

Hate to be pedantic, but that isn’t legal XSL-T 1.0 (though it may be in 1.1). You use this expression: “$styles[1]” etc, but the spec says:

“Variables introduce an additional data-type into the expression language. This additional data type is called result tree fragment…In particular, it is not permitted to use the /, //, and [] operators on result tree fragments.” (sec 11.1)

From a quick glance over, it looks like you can portably get the effect you intended by using following-sibling::*[1].

This is an intereting area of the XSLT spec, which has lead to a lot of confusion. In 11.2, it says that there are several ways to bind a variable:
# If the variable-binding element has a select attribute, […] the value of the variable is the object that results from evaluating the expression.
# If the variable-binding element does not have a select attribute and has non-empty content […] The content of the variable-binding element is a template, which is instantiated to give the value of the variable. The value is a result tree fragment

If you use the select attribute, the variable is bound to a node-set (if that is the result of evaluating the expression), and only if has content, it becomes a result tree fragment.