[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: "Tony Graham" <tgraham@xxxxxxxxxx>
Date: Thu, 1 Aug 2013 16:44:49 +0100 (IST)
Re:  Testing the Last Character of a String
On Thu, August 1, 2013 3:55 pm, 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?
>
> Thanks,
> Nathan
>
> <xsl:choose>
>     <xsl:when test="substring(archdesc/did/unittitle/text(),
> string-length(archdesc/did/unittitle), 1)=.">

This won't do the right thing if unittitle can end with '?', '!', or any
other punctuation character.

If unittitle can contain elements as well as text (i.e., contain mixed
content) then 'substring()' will blow up when you select multiple text
nodes.

>         <xsl:value-of select="normalize-space(archdesc/did/unittitle)"/>

And you'll lose the child elements, if any exist, when you do the
'normalize-space()'.

>         <xsl:text>&#160;</xsl:text>

As Liam said, it's redundant to repeat the '<xsl:text>&#160;</xsl:text>'.

>     </xsl:when>
>     <xsl:otherwise>
>         <xsl:value-of select="normalize-space(archdesc/did/unittitle)"/>
>         <xsl:text>.&#160;</xsl:text>
>     </xsl:otherwise>
> </xsl:choose>

Assuming there are no child elements but the title can end with other
punctuation characters:

<xsl:value-of select="normalize-space(archdesc/did/unittitle)"/>
<xsl:if test="not(matches(normalize-space(archdesc/did/unittitle),
'[.?!]$'))">
  <xsl:text>.</xsl:text>
</xsl:if>
<xsl:text>&#160;</xsl:text>

Regards,


Tony Graham                                   tgraham@xxxxxxxxxx
Consultant                                 http://www.mentea.net
Mentea       13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
 --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    XML, XSL-FO and XSLT consulting, training and programming

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.