Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT: node()? vs node()*

Tags:

xml

xslt

xslt-2.0

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.

like image 465
David Kaufman Avatar asked Sep 09 '26 07:09

David Kaufman


1 Answers

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.
like image 143
kjhughes Avatar answered Sep 11 '26 20:09

kjhughes