3

I've been working through some legacy code in XSLT in order to replace it with something in a more widely used language, and I've hit something about which I can't find a reference.

What's the difference between

<xsl:variable name="following_actions" as="node()*">

and

<xsl:variable name="following_actions" as="node()?">

I'm accustomed to seeing the asterisk version give me a list of records matching some condition specified in the body of the xsl:variable block, but I don't think I've seen the question-mark version before.

Directly relevant remedial references happily accepted. I believe I'm operating on XSLT 2.0, FWIW.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
David Kaufman
  • 989
  • 1
  • 7
  • 20
  • Section 9 of the XSLT 2.0 spec says that the "as" attribute is a sequence type; the syntax of sequence types is defined in section 2.5.3 of the XPath 2.0 spec. Your description of "a list of records matching some condition specified in the body of the `xsl:variable` block" suggests to me that you are trying to guess the semantics of the language rather than reading the specification; that seems a dangerous approach. – Michael Kay Dec 05 '17 at 00:17
  • True enough, although between the worked examples on live data I've got and some basic sense, there's usually a way to tease out the logic. And when I'm most uncertain of something, I sparingly lean on all you fine folks. Of all the code spelunking I've ever done, XSLT is where I'm having the hardest time acclimating to the structure of the basic documentation, so I appreciate the specificity of your suggested reference. – David Kaufman Dec 05 '17 at 14:15

1 Answers1

3

Like with regular expressions, ?, *, and + designate optionality and multiplicity:

  • node() means 1 node.
  • node()? means 0 or 1 nodes.
  • node()+ means 1 or more nodes.
  • node()* means 0 or more nodes.
kjhughes
  • 106,133
  • 27
  • 181
  • 240