[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Testing the Last Character of a String

Subject: Re: Testing the Last Character of a String
From: Liam R E Quin <liam@xxxxxx>
Date: Thu, 01 Aug 2013 11:03:46 -0400
Re:  Testing the Last Character of a String
On Thu, 2013-08-01 at 10:55 -0400, Nathan Tallman wrote:
> I'd like to test the last character in a node text-string. If it's a
> period, then insert the value and a space. If it's not a period, then
> insert the value, a period., and a space. I think I've gotten most of
> the code right, but don't have it quite right, as it's not working. Any tips?

> string-length(archdesc/did/unittitle), 1)=.">

In XPath, . is the current node, and '.' is a string consisting of a
full stop (US: Period).

Note also &#160; is not a space - it's a non-breaking space.
I'd put <xsl:text> </xsl:text> after the end of the xsl:choose element
if you want a normal space, since you want it in both cases. Yuo coud
then use an if instead of a choose. Note also that if the value ends in
a space, you use normalize-space to strip leading and trailing spaces
and collapse internal sequences of blanks to a single space, but you do
that _after_ looking at the last character.

<xsl:variable name="no-spaces"
   select="normalize-space(archdesc/did/unittitle)" />

<xsl:value-of select="$no-spaces" />

<xsl:if test="substring($no-spaces, string-length($no-spaces), 1) != '.'")>
  <!--* append a . if there was a non-dot at the end *-->
  <xsl:text>.</xsl:text>
</xsl:if>

<xsl:text> </xsl:text>

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.