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

Re: Find second character in a string (2)

Subject: Re: Find second character in a string (2)
From: "Paulo Henrique S. Bermejo" <bermejo@xxxxxxxxxxx>
Date: Fri, 31 Aug 2001 18:28:40 -0300
find last space in string
`Very Good Tom.!!!

Thanks!
----- Original Message -----
From: Thomas B. Passin
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Friday, August 31, 2001 12:45 PM
Subject: Re:  Find second character in a string (2)


[Paulo Henrique S. Bermejo]

I'm using this below script:

<xsl:variable name="var-nome-preparado" select="'Clark Jenier Foz'"/>
<xsl:value-of
select="substring-before(substring-after(substring-after($var-nome-preparado
, ' '), ' '), ' ')"/>

And I only need to get the string "Clark Jenier".
If someone have a solution, advice me.

[Tom]

I believe from your other posts that you want to separate the last name from
the other names, and output the last name first, perhaps capitalised. Here
is a styesheet that returns the last name and the other names separately.

Example:

XML file: <name>First Middle Third Last</name>

Results:
<results>

 Last name:

 {Last }

 First names:

 {First Middle Third }

</results>

The stylesheet uses recursion to find the last space in the string of names,
and gets all text after that as the last name (of course, you last name
better not end with a space).  It will work for any number of names, not
just first and last.

To get the other names, it gets the substring-before() the last name.

You could use these templates to re-order the names, to capitalize them, and
do other manipulations.

Cheers,

Tom P

Here's the stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding='utf-8'/>

<!--========= Driver template ======-->
<xsl:template match="/name">
<results>
 Last name:
     {<xsl:call-template name='getLastName'>
          <xsl:with-param name='string' select='text()'/>
     </xsl:call-template> }

 First names:
     {<xsl:call-template name='getFirstNames'>
          <xsl:with-param name='string' select='text()'/>
     </xsl:call-template>}
</results>
</xsl:template>

<!--======= Extract the last name ====-->
<xsl:template name='getLastName'>
    <xsl:param name='string'/>
     <xsl:variable name='notDoneYet' select='contains($string," ")'/>
     <xsl:choose>
          <xsl:when test='$notDoneYet'>
               <xsl:call-template name='getLastName'>
                    <xsl:with-param name='string'
select='substring-after($string," ")'/>
               </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
               <xsl:value-of select='$string'/>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>

<!--=== Extract the non-last names ====-->
<xsl:template name='getFirstNames'>
     <xsl:param name='string'/>
     <xsl:variable name='lastName'><xsl:call-template name='getLastName'>
      <xsl:with-param name='string' select='text()'/>
          </xsl:call-template></xsl:variable>
     <xsl:value-of select='substring-before($string,$lastName)'/>
</xsl:template>

</xsl:stylesheet>





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.