Name

[2.0] one-or-more()

Raises an error unless its argument is a sequence containing one or more items. This function can be used as a form of type checking. For example, we might have an <addressbook> element that’s required to have at least one <address> element. We could call one-or-more(address) with an <addressbook> element as the current item; if at least one <address> element isn’t present, the XSLT processor would raise an error.

Syntax

item()+ one-or-more(item()*)

Inputs

A sequence. If that sequence doesn’t have at least one item, one-or-more() raises an error.

Outputs

Assuming the input sequence has at least one item, one-or-more() returns that sequence. If the input sequence is the empty sequence, one-or-more() raises an error.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 15.2, “Functions That Test the Cardinality of Sequences.” More details about this function can be found in XQuery 1.0 and XPath 2.0 Formal Semantics section 7.2, “Standard Functions with Specific Static Typing Rules.”

Example

Here’s a simple stylesheet that illustrates the one-or-more() function:

<?xml version="1.0"?>
<!-- one-or-more.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="testSequence" as="item()*"> <xsl:sequence select="(3, 4, 5, current-date(), current-time(), 8, 'blue', 'red', xs:float(3.14), 42, xs:date('1995-04-21'))"/> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.