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 October 4th, 2007, 02:48 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default XSLT substrings

I've created a XSLT file to display list of books and sorted it alphabetically by title. I'm almost there. Here's my remaining problem. My output looks like this.

A Time to Kill
An Atom Away
Moby Dick
Stroke of Midnight
The Scarlet Letter

"A Time to Kill" should be the last item in the list because you don't file books by a starting "A", it should be alphabetized by "Time". And "The" should be ignored and filed under "Scarlet Letter" instead. I'm trying to use a substring function but I'm testing strings of varying length and then throwing them out if found... but only for sorting purposes, then sorting on the remainder and displaying the whole thing. [:S] I "should" wind up with this...

An Atom Away
Moby Dick
The Scarlet Letter
Stroke of Midnight
A Time to Kill

Am I making this harder than it needs to be? Or should I keep beating my head against it?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old October 4th, 2007, 05:29 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Like all text processing this is easier in XSLT 2.0 using regular expressions.

But if you have to use 1.0, I can't see why you would want to use substring(). The obvious approach is along the lines

<xsl:choose>
  <xsl:when test="starts-with($x, 'An ')">
     <xsl:value-of select="substring-after($x, 'An ')"/>

...etc

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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