Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 10th, 2007, 09:01 AM
Authorized User
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default substring-before() function.

Hello all,

I am trying to use the substring-before() function, but with no luck was wondering if anyone could help.

I have a separate xml file with data formatted the following:

test - test
testing testing testing

I am trying to use the substring-before only for the data which has ' - '.

I understand that according to the XPath specification's the substring-before function will return an empty string when it does not find the test string.

So my check is the following:

<xsl:when test="string-length(substring-before($wsc_text,' - ')) != 0">

My problem is that the check is not working for the data without the ' - '.

Sorry for the long post any help would be appreciated.

<xsl:when test="string-length(substring-before($wsc_text,' - ')) != 0">
Old July 11th, 2007, 05:33 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Use the contains() function to check that the substring exists before calling substring-before().

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to cut a substring petergoodman XSLT 2 July 17th, 2008 06:29 AM
substring in c# sudhirbharti C# 1 February 21st, 2008 01:29 PM
Substring-before with Regex bonekrusher XSLT 6 November 27th, 2007 01:16 PM
instead of substring what should we use in MSACCES miruthula SQL Language 1 February 9th, 2007 12:13 PM
SubString prasanta2expert Access VBA 1 November 17th, 2006 10:04 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.