Skip to Content
XSLT
book

XSLT

by Doug Tidwell
August 2001
Intermediate to advanced
480 pages
11h 16m
English
O'Reilly Media, Inc.
Content preview from XSLT

Name

substring-before() Function — Returns the substring of the first argument before the first occurrence of the second argument in the first argument. If the second argument does not occur in the first argument, the substring-before() function returns an empty string.

Synopsis

string substring-before(
               string
               string
               )

Inputs

Two strings. The first string is the string to be searched, and the second string is the string to be searched for in the first string.

Output

The portion of the first argument that occurs before the first occurrence of the second argument. If the second argument does not appear in the first argument, the function returns an empty string.

Defined in

XPath section 4.2, String Functions.

Example

This stylesheet uses the replace-substring named template. It passes three arguments to the replace-substring template: the original string, the substring to be searched for in the original string, and the substring to replace the target substring in the original string. The replace-substring template uses the contains(), substring-after(), and substring-before() functions extensively.

Here is our sample stylesheet. It replaces all occurrences of World with the string “Mundo”:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="test"> <xsl:call-template name="replace-substring"> <xsl:with-param name="original">Hello World!</xsl:with-param> <xsl:with-param ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XSLT

Learning XSLT

Michael Fitzgerald
Inside XSLT

Inside XSLT

Steven Holzner
XSLT Cookbook

XSLT Cookbook

Sal Mangano

Publisher Resources

ISBN: 0596000537Supplemental ContentCatalog PageErrata