1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-18 19:43:16 +00:00
Files
xslt-lab/site/content/xslt/functions/xpath-one-or-more.md
T
alexandrev-tibco 53e90ef86e feat(blog): complete XSLT/XPath reference — 229 function pages
Full coverage of XSLT 1.0, 2.0 and 3.0 elements and XPath functions:
- 59 XSLT elements (xsl:stylesheet → xsl:use-accumulators)
- 170 XPath functions (1.0 node/string/numeric/boolean, 2.0 sequence/
  date/QName/string, 3.0 HOF/map/array/JSON/streaming)
Each page: description, parameters table, return value, 2 runnable
Saxon examples with input XML + stylesheet + output, notes, cross-links.
xsltCompletions.js: all 229 entries now have blogSlug for hover links.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 09:28:05 +02:00

3.1 KiB

title, description, date, version, versionLabel, category, syntax, tags
title description date version versionLabel category syntax tags
one-or-more() Asserts that the sequence contains one or more items; raises a dynamic error if the sequence is empty. 2026-04-19T00:00:00Z 2.0 XSLT 2.0 sequence function one-or-more(sequence)
xslt
reference
xpath
xslt2

Description

one-or-more() is a cardinality assertion function. It returns its argument unchanged when the sequence contains at least one item, and raises a dynamic error (FORG0004) if the sequence is empty. The function has no effect on sequences of two or more items.

Use one-or-more() to document and enforce the assumption that a set of nodes must not be empty — for example when deriving a result from a required configuration element, or when a stylesheet would produce meaningless output if no input nodes matched. Asserting this explicitly makes the stylesheet self-documenting and avoids silent failures.

Parameters

Parameter Type Required Description
sequence item()* Yes The sequence that must contain one or more items.

Return value

item()+ — the original sequence, unchanged. Raises FORG0004 if the sequence is empty.

Examples

Enforcing required configuration

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <endpoint>https://api.example.com</endpoint>
  <endpoint>https://backup.example.com</endpoint>
</config>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/config">
    <urls>
      <xsl:for-each select="one-or-more(endpoint)">
        <url><xsl:value-of select="."/></url>
      </xsl:for-each>
    </urls>
  </xsl:template>
</xsl:stylesheet>

Output:

<urls>
  <url>https://api.example.com</url>
  <url>https://backup.example.com</url>
</urls>

Combining with string-join

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<tags>
  <tag>xslt</tag>
  <tag>xml</tag>
  <tag>xpath</tag>
</tags>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/tags">
    <xsl:value-of select="string-join(one-or-more(tag), ', ')"/>
  </xsl:template>
</xsl:stylesheet>

Output:

xslt, xml, xpath

Notes

  • The error code raised for an empty sequence is err:FORG0004.
  • one-or-more() is the XPath equivalent of a database NOT NULL or EXISTS constraint applied at transformation time.
  • When the stylesheet is intended to run against schema-validated documents, one-or-more() duplicates validation that the schema already performs; its value is greatest in schema-free environments.
  • Use zero-or-one() when zero items is acceptable, and exactly-one() when the count must be precisely one.

See also