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-concat.md
T
alexandrev-tibco b9d58ff7e0 feat(blog): XSLT/XPath function reference section (Phase 2)
- 19 reference pages under /xslt/functions/ covering:
  xsl:value-of, xsl:for-each, xsl:for-each-group, xsl:function,
  xsl:iterate, last(), position(), count(), concat(), contains(),
  substring(), sum(), key(), current(), string-join(), tokenize(),
  matches(), replace(), format-date()
- Each page: description, parameters table, return value, 2 runnable
  examples (input XML + stylesheet + output), notes, cross-links
- New Hugo section with reference-specific layout (version badges,
  syntax block, "Try in Playground" CTA, parameters table styles)
- Menu entry "Reference" → /xslt/functions/
- CSS: .ref-badge, .ref-syntax, .ref-index-list, .ref-try + table styles

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-18 14:38:55 +02:00

3.1 KiB

title, description, date, version, versionLabel, category, syntax, tags
title description date version versionLabel category syntax tags
concat() Concatenates two or more strings into a single string, accepting any number of arguments. 2026-04-18T00:00:00Z 1.0 XSLT 1.0 string function concat(str1, str2, ...)
xslt
reference
xslt1
xpath

Description

concat() joins two or more string arguments into a single string, in the order they are provided. Each argument is converted to a string using the XPath string-value rules before concatenation.

It requires at least two arguments but accepts any number. Arguments that are not strings (numbers, booleans, nodes) are automatically cast to their string representation.

concat() is the standard way to build dynamic attribute values, filenames, URIs, or any computed string in XSLT 1.0. In XSLT 2.0+, string-join() is often more readable when the separator is uniform.

Parameters

Parameter Type Required Description
str1 xs:anyAtomicType Yes First string (or value convertible to string).
str2 xs:anyAtomicType Yes Second string.
... xs:anyAtomicType No Additional strings; at least two arguments are required.

Return value

xs:string — all arguments concatenated in order, with no separator.

Examples

Build a full name

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <first>Jane</first>
  <last>Smith</last>
</person>

Stylesheet:

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

  <xsl:template match="/person">
    <xsl:value-of select="concat(first, ' ', last)"/>
  </xsl:template>
</xsl:stylesheet>

Output:

Jane Smith

Dynamic attribute value

Stylesheet:

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

  <xsl:template match="/person">
    <a href="{concat('/profile/', first, '-', last)}">
      <xsl:value-of select="concat(first, ' ', last)"/>
    </a>
  </xsl:template>
</xsl:stylesheet>

Output:

<a href="/profile/Jane-Smith">Jane Smith</a>

Concatenate node values and literals

<!-- Compose a greeting -->
<xsl:value-of select="concat('Hello, ', /person/first, '! You have ', count(//message), ' messages.')"/>

Notes

  • concat() does not add any separator between arguments. To join with a separator, either include the separator as a literal argument or use string-join() (XSLT 2.0+).
  • Unlike string-join(), concat() does not accept a sequence; each argument must be a single value.
  • Attribute value templates {expression} are a shorthand alternative for simple cases and can call concat() inside them.
  • Numbers are converted to their canonical string form: concat(1.0, 'x') produces "1x" not "1.0x" (the exact output depends on the XPath string conversion rules).

See also